Get List of Data Sets in Package in R (Example)

 

In this article, I’ll illustrate how to return a list of data sets in a particular package in the R programming language.

The tutorial looks as follows:

Let’s do this!

 

Example: Return All Data Sets Contained in a Package Using data() Function

This section shows how to get a list of all data sets that are provided by a certain add-on package.

For this example, we’ll use the ggplot2 package. We first have to install and load ggplot2:

install.packages("ggplot2")                                # Install & load ggplot2
library("ggplot2")

In the next step, we can apply the data() function to create a list of data sets that are contained in ggplot2:

data_list <- data(package = "ggplot2")$results[ , "Item"]  # Create list of packages
data_list                                                  # Print list of packages
#  [1] "diamonds"       "economics"      "economics_long" "faithfuld"      "luv_colours"    "midwest"        "mpg"            "msleep"         "presidential"   "seals"          "txhousing"

As you can see, the ggplot2 package provides many different data sets. One of them is the diamonds data set.

We can load this data set as shown below:

data(diamonds)                                             # Load diamonds data set
head(diamonds)                                             # Print head of diamonds data set

 

table 1 tbl_df get list data sets package

 

By executing the previous R programming syntax, we have returned the first six rows of the diamonds data set.

 

Video & Further Resources

If you need further explanations on the R code of this article, I can recommend having a look at the following video on my YouTube channel. I’m explaining the R codes of this article in the video:

 

 

Furthermore, you could have a look at the other tutorials on my website. I have published several tutorials about related topics such as variables, lists, and data elements.

 

In this tutorial you have learned how to print a list of data sets in a certain package in the R programming language. In case you have any further comments and/or questions, tell me about it in the comments below. Furthermore, please subscribe to my email newsletter to receive updates on the newest articles.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Top