Knowledge Quiz: Tutorial 1

Note
  • Click the check-mark button to check your answer.
  • Click the question-mark button to see an explanation of the solution.

Which command correctly uses pipes to compute the mean of the variable age in bfi?

  • NA
  • FALSE: This command incorrectly attempts to access age from the result of mean() called on bfi.
  • FALSE: This command incorrectly attempts to compute the mean of age directly on the bfi data frame using the base R pipe operator |>.
  • TRUE: This command correctly uses the base R pipe operator |> to pass bfi$age to the mean() function.
  • TRUE: This command correctly uses the pipe operator %>% to extract age from bfi and then computes the mean.

Which use of the placeholder . is valid when the data are not the first argument?

  • FALSE: The placeholder is incorrectly used after the function call.
  • FALSE: The placeholder is incorrectly used as a function.
  • FALSE: The placeholder is incorrectly used as the first argument.
  • FALSE: This use of the placeholder is the correct syntax for passing the data argument in a pipe, but it will not work with the base R pipe operator.
  • TRUE: This use of the placeholder is the correct syntax for passing the data argument in a pipe.

Using %>%, write (in one line) how you would compute the squared variance of the column bmi inside health, assuming bmi exists.

The correct code is health$bmi %>% var() %>% sqrt().

Using a pipeline, calculate the mean of the agree variable for participants who are older than 30 years. Use the WebR to write your code and insert the result in the box, rounding to two decimal places.

Round your answer to two decimal places.

The correct pipeline code to calculate the mean of the agree variable for participants older than 30 years is:

bfi %>% filter(age>30) %>% select(agree) %>% unlist() %>% mean()

After rounding, we get 4.84.

Back to top