Introduction to R

Introduction to R - ST 540 An Introduction to R Ryan T Elmore and Jennifer A Hoeting General R Info We will use the R statistical software in STAT

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 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 [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 LaTexcompile a entire script....
View Full Document

This note was uploaded on 06/16/2009 for the course STAT 540 taught by Professor Staff during the Spring '08 term at Colorado State.

Page1 / 6

Introduction to R - ST 540 An Introduction to R Ryan T Elmore and Jennifer A Hoeting General R Info We will use the R statistical software in STAT

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online