Only planets with rings (2)

You probably remember from high school that some planets in our solar system have rings and others do not. Unfortunately you can not recall their names. Could R help you out?

If you type rings_vector in the console, you get:

[1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE

This means that the first four observations (or planets) do not have a ring (FALSE), but the other four do (TRUE). However, you do not get a nice overview of the names of these planets, their diameter, etc. Let's try to use rings_vector to select the data for the four planets with rings.

Instruction

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

load(url("http://s3.amazonaws.com/assets.datacamp.com/course/intro_to_r/planets.RData")) rings_vector <- planets_df$rings # planets_df and rings_vector are pre-loaded in your workspace # Adapt the code to select all columns for planets with rings planets_df[rings_vector, "name"] # planets_df and rings_vector are pre-loaded in your workspace # Adapt the code to select all columns for planets with rings planets_df[rings_vector, ] msg <- "Do not remove or overwrite `planets_df` or `rings_vector`!" test_object("planets_df", undefined_msg = msg, incorrect_msg = msg) test_object("rings_vector", undefined_msg = msg, incorrect_msg = msg) test_output_contains('planets_df[rings_vector, ]', incorrect_msg = "Have you correctly adapted the code to select _all_ columns for the planets that have rings? You can use `planets_df[rings_vector, ]`. Make sure to include the comma here, it's crucial!") success_msg("Wonderful! This is a rather tedious solution. The next exercise will teach you how to do it in a more concise way.")

Remember that to select all columns, you simply have to leave the columns part inside the [ ] empty! This means you'll need [rings_vector, ].

Previous: 5-8 | Only planets with rings

Next: 5-10 | Only planets with rings but shorter

Back to Main