There are more than 100 datasets available in R, included in the datasets package. To see the list of available datasets, use data()
function. All available datasets in R can be accessed by their explicit names. This function also helps to access build-in datasets from other R packages (special module-based prebuild datasets).
This method has the following syntax, including some optional parameters.
data(...,
list = character(), # optional
package = NULL, # optional
verbose = getOption("verbose"), # optional
envir = .GlobalEnv, # optional
lib.loc = NULL, # optional
overwrite = TRUE) # optional
…
: These are names or strings.list, default= character()
: This is a character vector.package, default= NULL
: This is a vector to give the name of a package to load a particular dataset.lib.loc, default= NULL
: This is a set of directory names of R libraries. If set to NULL, data()
has excell to all libraries.verbose, default= getOption("verbose")
: If this is set to logical True, additional dataset info is printed.envir, default= .GlobalEnv
: This is the tool or environment where the dataset will be loaded.overwrite, default = TRUE
: This is used to replace names of different objects with the same name.This function returns a character vector of a specified dataset.
Now, let’s discuss the data()
function with a code example.
# program to load directly available datasets# invoking data() function from core Rdata("iris")# show first 8 rows of iris datasethead(iris, 8)
iris
dataset in our program.iris
dataset on the console.# program to load directly available datasets# invoking data() function from core Rdata(infert)# show first eight observations from infert datasethead(infert,8)
This dataset infert
has a dimension of 8 columns and 248 rows, which contains information about infertility based on gender, age, etc.
data(infert)
will load infert
dataset in this program.# Loadingdata(mtcars)# Print the first 6 rowshead(mtcars)
This mtcars
dataset contains information about motors: their design, fuel consumption, and performance. It has 11 columns and 32 rows in detail.
mtcars
dataset in this program.head()
function will print the top six entries from the dataset.RELATED TAGS
CONTRIBUTOR
View all Courses