next up previous
Next: About this document ...

R Lab 1

This lab is designed to be able to go through it on your own. If you come to the scheduled lab, we will get everyone started and then answer questions as they arise. You should try the commands on your own and not just read the text if you are unfamiliar with R. The exercises are generally to point out features of R that might be useful, or common mistakes; almost every exercise introduces a little something new. I would recommend you at least read through them. The beginning exercises will be need for later examples. If you are already familiar with R, there are still some handy tips sprinkled through.

Also, I have made a summary of useful commands by Category here. These do not describe the commands, but just give lists. Use the help function as described below to find out what they do.

Nuts & Bolts of Running R

Getting Started in R

R is a Command Line language, which means you type in the commands at the prompt ">" and the output comes after you hit return. In other words, there are not drop down menus and mouse commands. Even if you use the "Windows" version, it is still works basically this way. This gives you a lot of control, but can make it a little intimidating at first. It's often a good idea, if you are doing a lot of complicated things, to have another screen open (like Notebook) for text editing so that you can save your commands.

We are going to use preloaded data in this lab. To access it type the following command:

> library(MASS)
We are going to bring a particular set of data from the library into your R session: UScereal, a dataset about American cereals. So type at the prompt
> data(UScereal)

We also are going to want to save files into a folder for future reference. When I refer to mydir you should type in an appropriate directory. An example might be

"C:/Documents and Settings/lelandID/My Documents"

Note that Windows uses a " $ \backslash$" to separate subdirectories, unlike Unix, which uses "/". To give a full path name in R using Windows, you can use the Unix "/" or use " $ \backslash\backslash$". You cannot just use the Windows " $ \backslash$".

In the computer lab, we will give you instructions for what to insert in place of mydir. For more information about finding your working directory, etc., see http://www.stanford.edu/~epurdom/Saving/Saving.html

Plots

If you are working on the Leland prompt, it's important now that you have already set the environment display, Otherwise nothing will happen when you try to plot.

Writing Functions


next up previous
Next: About this document ...
Elizabeth Anne Purdom 2006-01-17