Access R Built-in Datasets: Quick Guide

To access the data sets that come with R, you can follow these steps:

  1. Firstly, you can use the data() function to view the list of built-in datasets in R. Input data() in the R console and press Enter to display the list of datasets.
  2. Choose a dataset that you are interested in. For example, suppose you want to read a dataset called mtcars.
  3. Read the dataset using the following code:
data(mtcars)

This will load the mtcars dataset into the R working environment, for use in subsequent code.

  1. Once the dataset is read, you can use the following code to view the contents of the dataset:
head(mtcars) # 显示数据集的前几行
summary(mtcars) # 显示数据集的摘要统计信息

These codes will display the first few rows or summary statistics of the dataset.

Note: In addition to using the built-in dataset, you can also read external datasets from sources such as CSV files or databases.

bannerAds