Quantcast

Learning R, returning the FALSE subset data.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Learning R, returning the FALSE subset data.

luisferlante
Hello there I am new to R and I have been playing around with a couple of tutorials.

One of the exercises goes as follows:
# Definition of vectors
name <- c("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune")
type <- c("Terrestrial planet", "Terrestrial planet", "Terrestrial planet",
          "Terrestrial planet", "Gas giant", "Gas giant", "Gas giant", "Gas giant")
diameter <- c(0.382, 0.949, 1, 0.532, 11.209, 9.449, 4.007, 3.883)
rotation <- c(58.64, -243.02, 1, 1.03, 0.41, 0.43, -0.72, 0.67)
rings <- c(FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE)

# Create a data frame from the vectors
planets_df <- data.frame(name, type, diameter, rotation, rings)

# Select the rings variable from planets_df
rings_vector <- planets_df$rings
 
# Print out rings_vector
rings_vector

# Adapt the code to select all columns for planets with rings
planets_df[rings_vector, ]

Until this last command, everything was fine, the command above would bring me all the planets where ring was  TRUE. But then I thought, what would be the command for it to bring the FALSE planets only.
The next exercise was about the of use subsets:

# Select planets with diameter < 1
subset(planets_df, diameter < 1)

So instinctively, I though this would work:
# Select planets without rings
subset(planets_df, rings = FALSE)

So could anyone shine a light on this?
Thank you for your time and patience.
Luis F.
Loading...