R has numerous datasets that are built-in and these datasets are available in a R package called “R Datasets Package“. This is maintained by R Core team and available with base installation of R. We can find the list of built-in datasets readily available in R using R function data().
Find out Builtin datasets in R with data()
If we use data() function without any arguments, we will get the list of built-in datasets.
data()
data() opens a tab/window listing all the built-in datasets. In total, we have 104 built-in datasets in R.
List of datasets in R Datasets Package with help()
We can also get the list of all Builtin datasets in R using help() function.
help(package="datasets")
Here we specify the datasets R package name and it opens a help window like this.
List of datasets in a specific R Package with data()
We can list the available dataset in any package as follows.
# list available datasets in ggplot2 package data(package="ggplot2")
List All Datasets from all available R packages
To list all available datasets from all R package we have available/installed in your computer is use the data() function with the following argument.
# how to list all datasets from all installed packages data(package = .packages(all.available = TRUE))
Accessing Built-In Dataset in R
We can directly access the builtin datasets using the name of the datasets
# access built-in dataset by its name mtcars ## mpg cyl disp hp drat wt qsec vs am gear carb ## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 ## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 ## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
Accessing a dataset from a R Package
We can access a dataset from a R package using the pattern packageName::datasetName. In this example below, we get storms data from dplyr package.
# access a dataset available in a package dplyr::storms ## # A tibble: 10,010 x 13 ## name year month day hour lat long status category wind pressure ## <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <chr> <ord> <int> <int> ## 1 Amy 1975 6 27 0 27.5 -79 tropi… -1 25 1013 ## 2 Amy 1975 6 27 6 28.5 -79 tropi… -1 25 1013 ## 3 Amy 1975 6 27 12 29.5 -79 tropi… -1 25 1013 ## 4 Amy 1975 6 27 18 30.5 -79 tropi… -1 25 1013 ## 5 Amy 1975 6 28 0 31.5 -78.8 tropi… -1 25 1012 ## 6 Amy 1975 6 28 6 32.4 -78.7 tropi… -1 25 1012 ## 7 Amy 1975 6 28 12 33.3 -78 tropi… -1 25 1011 ## 8 Amy 1975 6 28 18 34 -77 tropi… -1 30 1006 ## 9 Amy 1975 6 29 0 34.4 -75.8 tropi… 0 35 1004 ## 10 Amy 1975 6 29 6 34 -74.8 tropi… 0 40 1002 ## # … with 10,000 more rows, and 2 more variables: ts_diameter <dbl>, ## # hu_diameter <dbl>
Do you need more interesting, complex, and real world datasets? Check out TidyTuesday, a weekly social data project in R with really interesting datasets. You can also access the TidyTuesday project datasets from the R package tidyTuesdayR.
1 comment
Comments are closed.