This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Getting Started in R Phil Beineke, Balasubramanian Narasimhan, Victoria Stodden modified for R by Giles Hooker January 25, 2004 1 Overview R is a free alternative to Splus: a nice environment for data analysis and graphical exploration. It uses the object- oriented paradigm to implement much of its functionality, and this can be exploited in programming. Here are some aspects of its usefulness: Data management and storage Manipulation of vectors and matrices Tools for basic statistical analysis Customizable functions Graphical display Online help and other references This document provides a cursory introduction to each of these areas, enough to get the ball rolling. If you want additional introductory help, there is a web-based help that can be initialised by typing help.start() at the R-prompt. 2 Getting Started R is commonly run from a prompt on one of the Leland machines. In campus computer labs this is reached through the MacLeland and PCLeland programs. Once logged in, you can start a session on Samson. Next, you can open an X-Window. To do this, type setenv DISPLAY XX:0.0 , with XX replaced by the PC name on your computer. Then, enter xterm &amp; , and a window should appear. From here, R can be run from the Unix prompt by typing R ; however, you will probably prefer using R from within Emacs. Another alternative is to run R on the PCs themselves by opening it from the start menue. It can also be downloaded from http://cran.r-project.org/ to be used on other computers running Windows, MacOS or Linux. 3 Using R from Emacs The most efficient way to use R is from within Emacs using what is called R-mode . This is an enhanced mode for helping with all the common tasks associated with interactively using R. Fire up Emacs from your Unix prompt (e.g. using emacs hw1.r ) and type M-x R to invoke R . You will be prompted for a data directory. Usually, this will be /.Data , but a nice option is to keep a data directory for each problem set. You will then get an Emacs buffer with R running in it. You may want to work in R with the emacs window split in 2, one section for R and the other for programming. To split your emacs window, type C-x 2 . The recommended way to quit an R buffer is to type C-c C-q . A useful way to recall previous commands at the prompt is to use C-p or C-uparrow . 1 4 Reading Data A common task is reading in data from an external file. The function read.table is geared towards reading data into a data frame. The data file must conform in some ways. The first line should have a name for each column and every succeeding row must have a row label. Character strings containing blanks must be in quotes. The following prototype may be helpful....
View Full Document
This note was uploaded on 11/08/2009 for the course STATS 315B taught by Professor Friedman during the Spring '08 term at Stanford.
- Spring '08