r_dataframes Flashcards

1
Q

Create a data frame named “planets_df” with the following vectors:

  • name,
  • type,
  • diameter,
  • rotation,
  • rings
A

planets_df <- data.frame(name, type, diameter, rotation, rings)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Examine the structure of the “planets_df”

A

str(planets_df)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

For the data frame “planets_df”, print out the following:

  1. The diameter of Mercury: this is the value at the first row and the third column.
  2. From planets_df, select all data on Mars (the fourth row).
  3. The first 5 values in the “diameter” column of planets_df
A
  1. planets_df[1,3]
  2. planets_df[4,]
  3. planets_df[1:5, “diameter”]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Select the “rings” variable from “planets_df”. Store the vector that results as rings_vector.
  2. Select all columns for planets with rings
  3. Do this with the subset function
A
  1. rings_vector <- planet_df$rings
  2. planets_df[rings_vector,]
  3. subset(planet_df, subset = rings)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Adapt the code so that instead of only the name column, all columns for planets that have rings are selected.

A

planets_df[rings_vector,]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly