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 = "marginaleffects",
  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. library(marginaleffects)

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
247     carData TitanicSurvival Survival of Passengers on the Titanic 1309    4
289  causaldata         titanic  Data from the sinking of the Titanic 2201    4
323       COUNT         titanic                               titanic 1316    4
324       COUNT      titanicgrp                            titanicgrp   12    5
536    datasets         Titanic Survival of passengers on the Titanic   32    5
2121  Stat2Data         Titanic             Passengers on the Titanic 1313    6
2359        vcd       Lifeboats              Lifeboats on the Titanic   18    8
2415   vcdExtra        Titanicp             Passengers on the Titanic 1309    6
     n_binary n_character n_factor n_logical n_numeric
247         2           0        3         0         1
289         3           0        0         0         4
323         3           0        4         0         0
324         2           0        0         0         5
536         3           0        4         0         1
2121        3           0        3         0         3
2359        1           0        2         0         5
2415        2           0        3         0         3
                                                                                CSV
247  https://vincentarelbundock.github.io/Rdatasets/csv/carData/TitanicSurvival.csv
289       https://vincentarelbundock.github.io/Rdatasets/csv/causaldata/titanic.csv
323            https://vincentarelbundock.github.io/Rdatasets/csv/COUNT/titanic.csv
324         https://vincentarelbundock.github.io/Rdatasets/csv/COUNT/titanicgrp.csv
536         https://vincentarelbundock.github.io/Rdatasets/csv/datasets/Titanic.csv
2121       https://vincentarelbundock.github.io/Rdatasets/csv/Stat2Data/Titanic.csv
2359           https://vincentarelbundock.github.io/Rdatasets/csv/vcd/Lifeboats.csv
2415       https://vincentarelbundock.github.io/Rdatasets/csv/vcdExtra/Titanicp.csv
                                                                                 Doc
247  https://vincentarelbundock.github.io/Rdatasets/doc/carData/TitanicSurvival.html
289       https://vincentarelbundock.github.io/Rdatasets/doc/causaldata/titanic.html
323            https://vincentarelbundock.github.io/Rdatasets/doc/COUNT/titanic.html
324         https://vincentarelbundock.github.io/Rdatasets/doc/COUNT/titanicgrp.html
536         https://vincentarelbundock.github.io/Rdatasets/doc/datasets/Titanic.html
2121       https://vincentarelbundock.github.io/Rdatasets/doc/Stat2Data/Titanic.html
2359           https://vincentarelbundock.github.io/Rdatasets/doc/vcd/Lifeboats.html
2415       https://vincentarelbundock.github.io/Rdatasets/doc/vcdExtra/Titanicp.html
# View documentation in the browser
# get_dataset("Titanic", "Stat2Data", docs = TRUE)