Download and Read Datasets from marginaleffects or Rdatasets

Description

Downloads a dataset from the marginaleffects or the Rdatasets archives, and return it as a data frame. Opens the documentation as an HTML page. Search available datasets.

https://vincentarelbundock.github.io/Rdatasets/

Usage

get_dataset(dataset = "thornton", package = NULL, docs = FALSE, search = NULL)

Arguments

dataset

String. Name of the dataset to download.

  • marginaleffects archive: affairs, airbnb, ces_demographics, ces_survey, immigration, lottery, military, thornton, factorial_01, interaction_01, interaction_02, interaction_03, interaction_04, polynomial_01, polynomial_02

  • Rdatasets archive: The name of a dataset listed on the Rdatasets index. See the website or the search argument.

package String. Package name that originally published the data.
docs Logical. If TRUE open the documentation using getOption(“viewer”) or the Rstudio viewer.
search Regular expression. Download the dataset index from Rdatasets; search the "Package", "Item", and "Title" columns; and return the matching rows.

Value

A data frame containing the dataset.

Examples

library("marginaleffects")


dat <- get_dataset("Titanic", "Stat2Data")
head(dat)
  rownames                                          Name PClass   Age    Sex
1        1                  Allen, Miss Elisabeth Walton    1st 29.00 female
2        2                   Allison, Miss Helen Loraine    1st  2.00 female
3        3           Allison, Mr Hudson Joshua Creighton    1st 30.00   male
4        4 Allison, Mrs Hudson JC (Bessie Waldo Daniels)    1st 25.00 female
5        5                 Allison, Master Hudson Trevor    1st  0.92   male
6        6                            Anderson, Mr Harry    1st 47.00   male
  Survived SexCode
1        1       1
2        0       1
3        0       0
4        0       1
5        1       0
6        1       0
get_dataset(search = "(?i)titanic")
        Package            Item                                 Title Rows Cols
698     carData TitanicSurvival Survival of Passengers on the Titanic 1309    4
769  causaldata         titanic  Data from the sinking of the Titanic 2201    4
803       COUNT         titanic                               titanic 1316    4
804       COUNT      titanicgrp                            titanicgrp   12    5
1061   datasets         Titanic Survival of passengers on the Titanic   32    5
2954  Stat2Data         Titanic             Passengers on the Titanic 1313    6
3322        vcd       Lifeboats              Lifeboats on the Titanic   18    8
3378   vcdExtra        Titanicp             Passengers on the Titanic 1309    6
     n_binary n_character n_factor n_logical n_numeric
698         2           0        3         0         1
769         3           0        0         0         4
803         3           0        4         0         0
804         2           0        0         0         5
1061        3           0        4         0         1
2954        3           0        3         0         3
3322        1           0        2         0         5
3378        2           0        3         0         3
                                                                                CSV
698  https://vincentarelbundock.github.io/Rdatasets/csv/carData/TitanicSurvival.csv
769       https://vincentarelbundock.github.io/Rdatasets/csv/causaldata/titanic.csv
803            https://vincentarelbundock.github.io/Rdatasets/csv/COUNT/titanic.csv
804         https://vincentarelbundock.github.io/Rdatasets/csv/COUNT/titanicgrp.csv
1061        https://vincentarelbundock.github.io/Rdatasets/csv/datasets/Titanic.csv
2954       https://vincentarelbundock.github.io/Rdatasets/csv/Stat2Data/Titanic.csv
3322           https://vincentarelbundock.github.io/Rdatasets/csv/vcd/Lifeboats.csv
3378       https://vincentarelbundock.github.io/Rdatasets/csv/vcdExtra/Titanicp.csv
                                                                                 Doc
698  https://vincentarelbundock.github.io/Rdatasets/doc/carData/TitanicSurvival.html
769       https://vincentarelbundock.github.io/Rdatasets/doc/causaldata/titanic.html
803            https://vincentarelbundock.github.io/Rdatasets/doc/COUNT/titanic.html
804         https://vincentarelbundock.github.io/Rdatasets/doc/COUNT/titanicgrp.html
1061        https://vincentarelbundock.github.io/Rdatasets/doc/datasets/Titanic.html
2954       https://vincentarelbundock.github.io/Rdatasets/doc/Stat2Data/Titanic.html
3322           https://vincentarelbundock.github.io/Rdatasets/doc/vcd/Lifeboats.html
3378       https://vincentarelbundock.github.io/Rdatasets/doc/vcdExtra/Titanicp.html
# View documentation in the browser
get_dataset("Titanic", "Stat2Data", docs = TRUE)