University of Minnesota, Twin Cities     School of Statistics     Stat 3011     Rweb     Textbook (Wild and Seber)

Stat 3011 (Geyer) R

Contents

Downloading R

To download R go to CRAN (the Comprehensive R Archive Network) at

http://cran.r-project.org
or one of the mirror sites listed there. In particular the US mirror is
http://cran.us.r-project.org

Follow the intructions on the CRAN web pages. There are precompiled binaries for various forms of Windows (95, 98, NT, and 2000) and various forms of UNIX (including Linux).

Downloading R for Windows

Go to

http://cran.us.r-project.org/bin/windows/windows-9x/base/
and download the files
rw1021b1.zip
rw1021b2.zip
rw1021h.zip
rw1021ch.zip
rw1021w.zip
rwinst.exe
Then run the installer (double-click on the icon for rwinst.exe and navigate its wizard-like pages). Be sure to check the boxes for installing all the help, including the HTML help, which is not the default. And voila!

If you want anything else (contributed packages, documentation, and more), you'll have to start back at the CRAN page and read. We can't repeat it all here.

Downloading R for Linux

Go to

http://cran.us.r-project.org/bin/linux/
and choose the subdirectory that matches your distribution (and keep going down to further subdirectories until you find an rpm file or whatever binary format the distribution prefers. If you have RedHat 6.x Linux on an Intel-compatible box, for example, you get the file
http://cran.us.r-project.org/bin/linux/redhat/6.x/i386/R-base-1.2.1-2.i386.rpm
Then you just install it in the usual way: as root do
rpm -i R-base-1.2.1-2.i386.rpm

Using R

General

If you really want to know how to use R, you will have to download and print out the manuals from

http://cran.us.r-project.org/manuals.html
or buy and read one of the books listed on
http://www.r-project.org/books.html
We can't tell you how to use a really complicated computing language in one web page.

What we can do is tell you how, at least, to do whatever you were able to do in Rweb using R on your own computer.

Reading Data Files

The main issue is: How does Rweb read in the data, and how do I do the same thing. Suppose Rweb is loading the data from a URL, say

http://www.stat.umn.edu/geyer/somedata.txt
Rweb, being a web application can read URLs. R, not being a web application, can't. What to do?

First, download the data file to your computer (using a web browser).

Then, inside R you use the read.table function to read in the data, just like Rweb does. For example, if the file somedata.txt is in the current working directory, the following works.

X <- read.table("somedata.txt", header=TRUE)
attach(X)
plot(x, y)
abline(lm(y ~ x))

It should also be obvious that you can also read in files in the same format, each variable is one column of the file, the columns separated by white space, the variable name at the top of each column (that is, the first line of the file gives the variable names) that you yourself have created with a text editor or whatever.

On-Line Help

When you start up R, it tells you how to get on line help, for example

help(rnorm)
displays the help for the function rnorm, and
help.start()
starts a web browser pointing to the R help in web format (HTML).

Quitting and Saving Your Work

You quit R by typing the function

q()
as R says every time it starts up. You can also select "Exit" on the "File" menu of the Rgui program in Windows.

Before the program quits it asks

Save workspace image? [y/n/c]:
Type "y" to save your work. All the variables you have currently defined will be saved and reloaded when you start R again. Or type "n" to quit without saving.

Using R (Windows specific)

Starting R

Just click on one of the two icons Rgui or Rterm that are put in the folder bin of the main folder rw1021 made by the R installation process. I prefer Rgui (the nicer looking one). While you are at it, make a shortcut to this executable.

Working Directory

Set the working directory to the folder containing files you want to read by selecting "Change dir" on the "File" menu of the Rgui program.

Using R (UNIX specific)

Starting R

The name of the program is "R". Just type "R" at a UNIX prompt.

Putting it on a menu or as a desktop icon is a bit tricky. We won't try to tell you how to do that (and don't actually know ourselves).