Multiple Choice Questions for Subsetting in R
My MCQs are based off the Analyzing Patient Data lesson on R Programming, starting more simply with vectors and then moving to matrices.
Given the following line of code used to generate vector ‘x’, how would you subset the first element?
x <- c(10, 20, 30)
Given the following line of code to generate matrix ‘y’, how would you subset the second row?
y <- matrix(nrow=2, ncol=3, 1:6)
- A. the
nrowargument is used in the function for generating the matrix, not in subsetting an object
- B. this is the incorrect number of dimensions (1); there should be a comma to index both the row(s) and column(s) in the 2-dimensional matrix
- C. the second column has been subset instead of the second row
- D. correct answer