WorksheetsTutorial -1 (UNIT-I): Vectors in R
Total questions: 10
Worksheet time: 5mins
In R, which code correctly declares a numeric vector of three elements 2, 4, and 6?
v := {2, 4, 6}
v <- vector(2,4,6)
v = [2, 4, 6]
v <- c(2, 4, 6)
Which statement best describes the difference between a scalar and a vector in R?
A scalar stores lists, a vector stores matrices
A scalar is character, a vector is numeric
A scalar holds one value, a vector holds multiple
A scalar is mutable, a vector is constant
What is the output of length(c(3, 5, 7, 9)) in R?
3
5
Error
4
Given x <- c(1,2,3) and y <- c(10,20,30), what is x + y?
c(1,2,3,10,20,30)
c(10,20,30)
c(9,18,27)
c(11,22,33)
Which R code uses help to view documentation for the c function?
help('c')
help(c)
All of the above
?c
If x <- c(TRUE, FALSE, TRUE) and y <- c(FALSE, TRUE, TRUE), what is x & y?
c(TRUE, FALSE, TRUE)
c(FALSE, TRUE, FALSE)
c(TRUE, TRUE, TRUE)
c(FALSE, FALSE, TRUE)
Which result demonstrates R’s vector recycling when adding c(1,2) to c(10,20,30,40)?
Error due to unequal lengths
c(11,22,30,40)
c(11,22,12,22)
c(11,22,31,42)
What does c() do in R?
Casts a vector to numeric
Combines values into a vector
Counts elements in a vector
Copies a vector to memory
Which operation is valid element-wise on two equal-length numeric vectors in R?
Addition with +
Concatenation with ++
Matrix multiplication with **
Indexing with =>
With x <- c(2,4,6) and a scalar s <- 3, what is x * s?
c(6,12,18)
c(2,4,6,3)
c(5,7,9)
Error: cannot multiply
