Data Sets in Base R
R already has a collection of datasets available to you. You can save some time by using these datasets instead of inputting example data manually. You will also notice that many example applications of R functions (given in the section Examples of the R function's help page or online such as on the StackExchange website) use these datasets for demonstrations. Moreover, some R packages supply additional datasets.
R comes with many data sets preloaded in the datasets
package, which comes with base R. These data sets are not very
interesting, but they give you a chance to test code or make a point
without having to load a data set from outside R. You can see a list of
R's data sets as well as a short description of each by running:
help(package = "datasets")
To use a data set, just type its name. Each data set is already presaved as an R object. For example:
iris
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
However, R's data sets are no substitute for your own data, which you can load into R from a wide variety of file formats. But before you load any data files into R, you'll need to determine where your working directory is.
Source: G. Grolemund, https://rstudio-education.github.io/hopr/dataio.html
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 License.