Vous êtes sur la page 1sur 4

Introduction to R

R is a computer language for statistical computing. It is free, and most


new statistics methods are developed and made available in R.
Learning about R
There are many sources to learn about R, lots of them free. Here are a
few that I like.
"Using R for Introductory Statistics" is a free tutorial by John Verzani:
cran.r-project.org/doc/contrib/Verzani-SimpleR.pdf
Quick-R tutorial website:
http://www.statmethods.net/index.html
This Quick-R website has lots of good tutorials. It was developed by
Robert Kabacoff, who wrote a book "R in Action", that expands on the
material in the website. You can get a 38% discount on the book at the
website (making it about $40).
There are many tutorials on R on youtube. Go to youtube.com and
search for "R tutorial", and "r statistics".
Recommended textbooks
Murray Logan. Biostatistical Design and Analysis Using R.
Robert Kabacoff. R in Action.
Installing R
These course files have instructions for installing R for Mac or
Windows.

How to install R for Mac.docx


How to install R for Windows.docx

You can download the R software from the R project web page
http://www.r-project.org
This is the main site for information on R. At this site are directions for
installing R, accompanying packages and other sources of

documentation. Instructions for installing R for Linux are on this


website.
Starting R on your computer
I use R on a Windows machine, so I'll illustrate that. For Linux or Mac,
follow the instructions in the installation.
To start R in Windows, click on the R icon on the desktop or find the R
program under the start menu.
The greater than symbol ">", called the caret, is the R prompt. Type
commands after the caret and press "Enter". R will display the results.
Use the help() function to get documentation.
> help()
Use the help() function get documentation on R functions. For example,
to get documentation on the "mean" function to calculate an average:
> help(mean)
Packages
The base version of R that you installed has all the basic statistics
functions. However, there are many packages that extend the base
functionality. Here is an example of how to download and install a
package for R.
How to load data sets from the Dalgaard text ISwR package. (Dalgaard
Chapter 2)
Peter Dalgaard's text "Introductory Statistics with R" has data sets that
we'll use for class. They are in a package named ISwR. To make these
available, do the following (described in Dalgaard Appendix A).
1. Install the ISwR package on your computer. You only need to do this
once. Notice the quote marks around "ISwR".
> install.packages("ISwR")

If you have write permission in the necessary files, R will prompt you to
select a mirror site from which to download the ISwR package. If so,
skip this next material on choosing a personal library.
Choose a personal library (if required by R)
If you do not have write permission in the necessary files, you will get
the following error message:
Warning in install.packages("car") : 'lib = "C:/Program Files/R/R3.0.2/library"' is not writable
Error in install.packages("car") : unable to install packages
R will ask "Would you like to use a personal library instead?" Click Yes.

R will offer to create a personal library in your user directory. Click Yes.

After that, R will prompt you to choose a mirror site for the download.
This is the end of material on choosing a personal library.
R will prompt you to select a mirror site from which to download the
ISwR package. Choose one near your location. The output should look
something like this.
> install.packages("ISwR")
--- Please select a CRAN mirror for use in this session ---

trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.6/ISwR_2.0-2.zip'
Content type 'application/zip' length 281819 bytes (275 Kb)
opened URL
downloaded 275 Kb
package 'ISwR' successfully unpacked and MD5 sums checked
The downloaded packages are in
C:\Documents and Settings\Michael Walker\Local
Settings\Temp\RtmplnWoP0\downloaded_packages
updating HTML package descriptions

2. After you have installed the ISwR package, you need to load it into R
each time you start a new R session. To do this, use the library()
function. Notice that there are no quote marks around (ISwR).
> library(ISwR)
Look at the data sets in the ISwR package.
> data(package = "ISwR")
You can look at all the data sets currently loaded into your R session.
> data(package = .packages(all.available = TRUE))
Dalgaard Appendix B describes all the data sets. If you know the name
of the data set, such as the malaria data set, you can use the help
function:
> help(malaria)

Vous aimerez peut-être aussi