R Data Set
R provides various datasets for practice and analysis, accessible through packages like datasets
. You can load these datasets to explore and analyze them using built-in R functions.
Key Topics
Loading a Data Set
You can load datasets from the datasets
package using the data()
function.
# Loading the 'mtcars' dataset
data("mtcars")
# Displaying the first few rows
head(mtcars)
Output:
The first few rows of the 'mtcars' dataset.
Code Explanation: The data()
function loads the mtcars
dataset, and head()
displays the first few rows.
Exploring a Data Set
Use functions like summary()
and str()
to explore the structure and summary statistics of a dataset.
# Exploring the dataset
summary(mtcars)
str(mtcars)
Output:
Summary statistics and structure of the 'mtcars' dataset.
Code Explanation: The summary()
function provides summary statistics, and str()
shows the structure of the mtcars
dataset.
Key Takeaways
- R provides built-in datasets for practice and analysis.
- Use the
data()
function to load datasets. - Functions like
head()
,summary()
, andstr()
help explore the data.