Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a list of built-in data sets in R?

Tags:

r

r-faq

dataset

Can someone please help how to get the list of built-in data sets and their dependency packages?

like image 342
mockash Avatar asked Nov 19 '15 07:11

mockash


People also ask

How do you list the preloaded datasets in R?

To get the list of available data sets in base R we can use data() but to get the list of data sets available in a package we first need to load that package then data() command shows the available data sets in that package. Also, for data sets in base R, we can use ls("package:datasets").

How do I get inbuilt data in R?

The default R datasets included in the base R distribution Simply check the checkbox next to the package name to load the package and gain access to the datasets. You can also click on the package name and RStudio will open a help file describing the datasets in this package.

What function is used for getting list of all in built datasets in R?

data() function will list the datasets of all loaded packages.


1 Answers

There are several ways to find the included datasets in R:

1: Using data() will give you a list of the datasets of all loaded packages (and not only the ones from the datasets package); the datasets are ordered by package

2: Using data(package = .packages(all.available = TRUE)) will give you a list of all datasets in the available packages on your computer (i.e. also the not-loaded ones)

3: Using data(package = "packagename") will give you the datasets of that specific package, so data(package = "plyr") will give the datasets in the plyr package


If you want to know in which package a dataset is located (e.g. the acme dataset), you can do:

dat <- as.data.frame(data(package = .packages(all.available = TRUE))$results) dat[dat$Item=="acme", c(1,3,4)] 

which gives:

    Package Item                  Title 107    boot acme Monthly Excess Returns 
like image 174
4 revs Avatar answered Oct 19 '22 07:10

4 revs