We can use the names()
function to see all the variables available to us within the Auto
dataset.
> names(Auto)
[1] "mpg" "cylinders" "displacement" "horsepower" "weight" "acceleration" "year" "origin"
[9] "name"
To refer to a variable, we must type the data set and the variable name
joined with a $
symbol.
Auto$cylinders
...
Alternatively, we can use the attach()
function in
order to tell R to make the variables in this data frame available by name directly.
attach(Auto)
cylinders
...
Try calling the mpg variable of the Auto dataset. Assume that the Auto dataset has been loaded and attached.