How to import the mtcars dataset in R language?
In R language, you can import the built-in mtcars dataset into the R environment using the following code:
data(mtcars)
This line of code loads the mtcars dataset into a data frame named `mtcars`. The mtcars dataset is an example dataset in R that includes information on 32 cars such as fuel efficiency, horsepower, and displacement.
After importing, you can access and manipulate the dataset by using the `mtcars` object, for example:
# 查看数据集的前几行head(mtcars)
# 查看数据集的结构
str(mtcars)
# 计算并打印平均马力
mean(mtcars$hp)
# 绘制散点图展示马力与燃油效率之间的关系
plot(mtcars$hp, mtcars$mpg)
The above examples demonstrate some simple ways to manipulate and analyze the mtcars dataset. You can further use and process this dataset according to your own needs.