Using Sample Datasets Installed in R

Leave a comment

R has built-in datasets which can be useful for learning R. Let’s take a look at these.

From RGui, let’s see the packages installed by going to Load package:

We can see datsets and MASS are installed:

From RStudio we can see the same thing:

We can use datasets right away as the library is loaded.

In RGui or RStudio, type in:

data()

This will display the datasets installed in the package.

RGui:

RStudio:

We can see the data in these datasets by typing the dataset name. For example, for the dataset Orange, we can type Orange into the Console:

Using View, we can see the data in a window which allows us to filter the data:

View(Orange)

Filter to age = 484:

This displays the filtered data:

Let’s use the MASS package. Click on MASS to get help on the package:

We can see there are many datasets available, including one called abbey, which shows “determinations of nickel content in a Canadian syenite rock”.:

We can’t simply use this the same way as we did with datasets, where we type in the dataset name, or we get an object not found error:

In this case, we need use library first, then we can use it:

library(MASS)

You may find these datasets useful when you want to try new things with R.

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

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