12.4 Load data that is in another R package

12.4.1 Packages that come with R

  • Many scientists develop software for R, and they often include datasets to demonstrate how the software works.
  • Some of this software, called a “package” comes with R already and just needs to be loaded.
  • This is done with the library() command.
  • The MASS package comes with R when you download it and has many useful functions and interesting datasets.
library(MASS) #Load the MASS package

MASS contains a dataset called called “mammals”

data(mammals)

You can confirm that the mammals data is in your workspace using ls()

ls()

You should now have both the “iris”" and the “mammals”" data in your R “workspace.”"

What is in the mammals dataset? Datasets actually usually have useful help files. Access help using the ? function.

The help screen will pop up either within RStudio, or possibly in your web browser. It tells us that mammals is

“A data frame with average brain and body weights for 62 species of land mammals.”

Since this is someone else’s data, the authors of the MASS package need to provide proper citation. At the bottom we can see that these data come from the paper:

Allison, T. and Cicchetti, D. V. (1976) Sleep in mammals: ecological and constitutional correlates. Science 194: 732-734.

We can learn about the mammals data using the usual commands

dim(mammals)
names(mammals)
head(mammals)
tail(mammals)
summary(mammals)