{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Introduction to R - ST 540 An Introduction to R Ryan T...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
ST 540: An Introduction to R Ryan T. Elmore and Jennifer A. Hoeting August 22, 2007 General R Info We will use the R statistical software in STAT 540. R is a platform-independent (runs on Windows, Mac, and Unix/Linux), freeware version of S-Plus. You can download R from the R Project website at www.r-project.org for free! In other words, you should have no trouble finding a copy of R to use provided that you can find a computer. R is installed on most, if not all, community computers in the Statistics Building. There is quite a bit of free documentation available at the R website, or, if you want to spend money, you can find books on R too. Once you have installed R , it is probably a good idea to create separate working direc- tories for your various courses. For example, you might want to create a directory called STAT540, or something along those lines. It is not a bad idea to create subdirectories within this directory so that you don’t “mask” objects or create other problems. If you go this route, you will have to change your working directory to your STAT540 directory in order for the objects to be saved there. You can change your working directory using menus or by using the setwd() command. Saving your work You’ll need to save your code for two reasons. First, we’ll reuse a lot of the commands in this class, so you’ll want to refer to your previous assignments. Second, you’ll need to turn in a clean version of your final code with every assignment that requires computing. There are 2 options for saving your work. As described below, you might end up using a combination of both options, depending on your goals for a particular R session. 1. Use Microsoft Word (or your favorite text editor like notepad, vi, emacs, etc. ). a. Open a blank Word document by clicking on the Word icon. b. Write the necessary commands in R to carry out the analyses below and then cut and paste the answer into your Word document. c. Example of output cut and pasted into a Word document: Part a. Create a vector N of normal random variables of length 20 > N =rnorm(20) > N 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
[1] 0.91499114 -0.34835346 -1.03180584 [4] 0.92598610 -0.02966679 1.47782338 [7] -0.17697113 0.64280212 -0.70764661 [10] -0.60311414 0.54913008 -2.24526009 [13] 0.75785810 1.78372173 -0.30530967 [16] -1.19859043 -0.73382970 1.11611613 [19] 0.36869011 0.54810743 2. R scripts a. Within R, use the menus: File New script b. Type your commands in the script window and run the commands like I showed you in class c. Copy and paste your output from the command window into your script window. 3. Pros and Cons: The advantage of Word is that you can copy and paste plots into Word and can make your output pretty. A lot of students write their entire assignment in Word which makes it look nice (which never hurts your grade!). The advantage of using R scripts is that you can execute the code in R, so you can do things like compile a entire script. I use a combination of R scripts and either Word or LaTex documents.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern