R Frequently Asked Questions
How can I see what data sets are available when I start R?

Once you start your R program, there are example data sets available within R along with loaded packages.  You can list the data sets by their names and then load a data set into memory to be used in your statistical analysis. For example, in the book "Modern Applied Statistics with S" a data set called phones is used in Chapter 6 for robust regression and we want to use the same data set for our own examples. Here is how to locate the data set and load it into R.
Command library loads the package MASS (for Modern Applied Statistics with S) into memory. Command data() will list all the datasets in loaded packages. The command data(phones) will load the data set phones into memory.
library(MASS)
data()

Data sets in package 'datasets':
AirPassengers           Monthly Airline Passenger Numbers 1949-1960
BJsales                 Sales Data with Leading Indicator
BJsales.lead (BJsales)
                        Sales Data with Leading Indicator
BOD                     Biochemical Oxygen Demand
CO2                     Carbon Dioxide uptake in grass plants
ChickWeight             Weight versus age of chicks on different diets
DNase                   Elisa assay of DNase
EuStockMarkets          Daily Closing Prices of Major European Stock
                        Indices, 1991-1998
........ (more data sets in between are omitted.)
uspop                   Populations Recorded by the US Census
volcano                 Topographic Information on Auckland's Maunga
                        Whau Volcano
warpbreaks              The Number of Breaks in Yarn during Weaving
women                   Average Heights and Weights for American Women
Data sets in package 'MASS':
Aids2                   Australian AIDS Survival Data
Animals                 Brain and Body Weights for 28 Species
... (more data sets are omitted here)
oats                    Data from an Oats Field Trial
painters                The Painter's Data of de Piles
petrol                  N. L. Prater's Petrol Refinery Data
phones                  Belgium Phone Calls 1950-1973
quine                   Absenteeism from School in Rural New South
                        Wales
... (more data sets are omitted here)

Use 'data(package = .packages(all.available = TRUE))'
to list the data sets in all *available* packages.

data(phones)

phones

$year
 [1] 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
$calls
 [1]   4.4   4.7   4.7   5.9   6.6   7.3   8.1   8.8  10.6  12.0  13.5  14.9
[13]  16.1  21.2 119.0 124.0 142.0 159.0 182.0 212.0  43.0  24.0  27.0  29.0

How to cite this page

Report an error on this page or leave a comment

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.