You are on page 1of 3

Libraries in R

There is a great graph someone on the internet made about R versus other stat packages:

The point being that R is the most difficult to learn but also the most powerful so the initial work
learning R is worth it at the end. Try not to get intimidated by R and think of it as a fancy
graphing calculator.

One of the most powerful features of R is that the functionality of R can be extended, usually by
code that is also written in R. That is, people around the world create what are called R packages
(there are over 900 of them from analyzing genetic data to pricing stock options).

In the following we show you how to install packages and use them.
The Dotplot Function

You would think that the basic doltplot is built into R like the histogram. Nope. There is a nice
dotPlot function but it is hidden inside the BHH2 package. In R do the following.

> install.packages("BHH2")

This just has to be done once to install the package. To use the package you then have to say.
> library(BHH2)

All the routines in this package are now available to you. All we care about is the dotplot
function. If one cared about all the functions available in the package enter the following
command:

> help(package=BHH2)

Example

> mydata=read.csv("http://people.fas.harvard.edu/~mparzen/stat104/cars10.csv")
> names(mydata)
[1] "make" "price" "mpg" "headroom" "trunk"
[6] "weight" "length" "turn" "displacement" "gear_ratio"
[11] "foreign"
> dotPlot(mydata$price)
The Describe Function

The summary() function in R is ok but doesn’t give you as much information as I would like.
Luckily, there is a nice function called describe from the psych package. In R do the
following.

> install.packages("psych")

This just has to be done once to install the package. To use the package you then have to say.
> library(psych)

All the routines in this package are now available to you. All we care about is the describe
function. If one cared about all the functions available in the package enter the following
command:

> help(package=psych)

Example

> mydata=read.csv("http://people.fas.harvard.edu/~mparzen/stat104/cars10.csv")
> names(mydata)
[1] "make" "price" "mpg" "headroom" "trunk"
[6] "weight" "length" "turn" "displacement" "gear_ratio"
[11] "foreign"
> describe(mydata$price)
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 74 6165.26 2949.5 5006.5 5614.17 1358.06 3291 15906 12615 1.62 1.69 342.87

You might also like