Multiple Choices: Vectors
Questions
- What function is commonly used to create a sequence of numbers in a vector? ::: {.cell}
- Which function combines multiple values into a single vector in R?
- What will be the output of the following code:
c(1, 2, 3) + c(4, 5, 6)
?
- Which function is used to determine the type of elements in a vector?
- What will be the output of
length(c(10, 20, 30, 40))
?
- If
x <- c(5, 10, 15, 20, 25)
, what is the output ofx[2]
?
- What is the result of
sum(c(2, 4, 6, 8, 10))
?
- Which of the following functions will check if an object is a vector?
- What will be the result of
c(1, 2, 3) * 2
?
- If
y <- c("apple", "banana", "cherry")
, what is the result ofy[2:3]
?
- What is the output of the following code:
rep(1, times = 5)
?
- What does the function
mean()
do when applied to a numeric vector?
- What will be the output of
c(1, 2, 3) > 2
?
- Which function would you use to remove duplicate elements from a vector in R?
- If
z <- c(1, 2, NA, 4)
, what will be the result ofmean(z, na.rm = TRUE)
?
- Which operator will concatenate two vectors in R?
- What will be the output of
c(TRUE, FALSE, TRUE) & c(TRUE, TRUE, FALSE)
?
- What does
sum(c(TRUE, FALSE, TRUE, FALSE, TRUE))
return?
- Which function would you use to reverse the order of elements in a vector?
- If
x <- c(3, 6, 9, 12, 15)
, what doesx[x > 9]
return?
- What is the result of
c(1, "2", 3)
in R?
- Which function would you use to repeat each element of a vector a specified number of times?
- What will
x[1:3] <- c(10, 20, 30)
do tox <- c(1, 2, 3, 4, 5)
?
- What will the expression
1:5 * 2
return?
- What is the output of
which(c(FALSE, TRUE, FALSE, TRUE))
?
- What will be the output of
any(c(FALSE, FALSE, TRUE))
?
- What will
x <- c(5, 10, 15); y <- x * x > 25
sety
to?
- What is the result of
c(1, 2, NA, 4) == NA
in R?
- Which function would you use to sort a vector in ascending order?
- If
z <- c("a", "b", "c", "d")
, what doesz[c(FALSE, TRUE, TRUE, FALSE)]
return?
:::