R Quick Syntax Reference by Margot Tollefson

R Quick Syntax Reference by Margot Tollefson

Author:Margot Tollefson
Language: eng
Format: epub, pdf
ISBN: 9781484244050
Publisher: Apress


R Datasets

Many of the packages in R come with datasets. Some of these datasets are found in the package datasets, which is one of the packages installed by default in R. To access datasets from the package datasets, enter library(datasets) at the R prompt or check the box to the left of datasets under the “Packages” tab in R Studio. To see the datasets in datasets, enter library(help=datasets) at the R prompt or select datasets under the “Packages” tab. Once the library is loaded, the datasets in datasets are accessible.

You can also use the function attach() to get access to a dataset in a library without loading the library. Both the package and the dataset names are required, separated by two colons and unquoted, for example, attach(datasets::attitude). Attached datasets should be detached after you are done with them, for example, detach(datasets::attitude).

For any library, once the library is loaded, the datasets in the library are accessible like any other object in the workspace. A dataset can be an atomic object, a data.frame, or a list. The function attach() gives an error if the dataset is not a data frame or list, but the object is available just by using the name of the object if the library is loaded. In R Studio, the datasets do not appear under the “Environment” tab, however, so the datasets are not in the workspace. Use the data() function to load the data into the workspace, as seen previously.

The attach() function attaches into a certain position in the workspace. R searches for objects through positions in the workspace. Position one is the workspace. The first attach() call attaches in position two, the second position three, and so on. A position may be specified in the call. R uses the first object with the name that it finds, starting with position one.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.