Only planets with rings
You will often want to select an entire column, namely one specific variable from a data frame. If you want to select all elements of the variable diameter, for example, both of these will do the trick:
planets_df[,3]
planets_df[,"diameter"]
However, there is a short-cut. If your columns have names, you can use the $ sign:
planets_df$diameter
This exercise is part of the course
Introduction to R
Exercise instructions
- Use the
$sign to select theringsvariable fromplanets_df. Store the vector that results asrings_vector. - Print out
rings_vectorto see if you got it right.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# planets_df is pre-loaded in your workspace
# Select the rings variable from planets_df
rings_vector <-
# Print out rings_vector