Which of this phrases regarding the operators [], [[]], and $ when subsetting a data frame are true?
- Incorrect. You can use logical conditions with both
[]andfilter()but not$or[[]]. - Incorrect.
$works only with column names, not numbers. - Incorrect.
[]works perfectly with data frames. - Correct. This is a key distinction between these operators.
- Incorrect. They differ in syntax, output type, and flexibility.
Write a single line of base R code that returns a data frame containing only the rows of bfi where age is less than 50, gender is equal to 1, and education is not missing and greater than or equal to 4. The code must keep exactly the three columns gender, age, and education in that order. You must use only base R subsetting syntax.
The required R code is: bfi[age < 50 & gender == 1 & !is.na(education) & education >= 4, c("gender", "age", "education")]
Using dplyr, how would you select only female participants under 25 years old from the bfi dataset? (Multiple answers may be correct.)
- Correct. The
&operator gives the same result as commas. - Correct. The order of conditions does not matter.
- Incorrect.
filtermust be a function, not an index argument. - Incorrect. While this base R syntax works, it is not using
dplyr. - Incorrect. While this base R syntax works, it is not using
dplyr.