R uses many types to brackets for different purposes and it is initially challenging to differentiate between specific uses.
These questions draw from information gained in Analyzing Patient Data and Creating Functions
-
If
x <- c(1,3,6,34,2,3,5,76,3,4,5,6,7,9)
which answer below will create a custom function that will calculate the mean of the first “y” numbers?mean_first_y <- function(X,Y){mean(x[1:Y])}
mean_first_y <- function(X,Y)(mean(x[1:Y]))
mean_first_y <- function(X,Y)mean(x[1:Y])
- all of the above
-
If
x <- c(1,3,6,34,2,3,5,76,3,4,5,6,7,9)
which answer below will calculate the mean of the first 3 numbers in x?mean[x[1:3]]
mean{x[1:3]}
mean(x{1:3})
mean(x[1:3])
mean(x{1:3})
For question 2, the distractors are:
- The student has not understood that functions are followed by
()
- The student has not understood that functions are followed by
()
- The student has not understood that vectors are subsetted by using
[]
mean(x[1:3])
is the correct answer- The student has not understood that vectors are subsetted by using
[]