1. Learn
  2. /
  3. Courses
  4. /
  5. Basic Statistics

Exercise

Indexing and selecting columns from a dataframe

In the same way as you indexed your vectors, you can select elements from your dataframe using square brackets. Different from dataframes however, you now have multiple dimensions: rows and columns. That's why you can use a comma in the middle of the brackets to differentiate between rows and columns. For instance, the following code planet_df[1,2] would select the element in the first row and the second column from the dataframe planet_df.

You can also use the $ operator to select an entire column from a dataframe. For instance, planet_df$planets would select the entire planets column from the dataframe planet_df.

Instructions

100 XP
  • Select the elements in the first row, and the second and third column from planet_df
  • Select the entire third column from planet_df