# Create a random integer vector of length 5
x <- sample(1:100, 5)
# Ask for the following index between 1:5
idx <- sample(1:5, 1)
# Wrong answers
wrong <- sample((1:5)[-idx], 2)
# The correct answer:
res <- x[idx]

Question

Vector subsetting in R. We can access elements/values in a vectur using vector subsetting by index. Imagine we have the following vector x:

print(x)

If we call x[r idx], what is the resulting value?

Answerlist

Solution

x[r idx] returns the r idxth element of the vector x which is r x[idx].

Answerlist

Meta-information

exname: Vector subsetting extype: schoice exsolution: 001 exshuffle: True



Try the c403 package in your browser

Any scripts or data that you put into this service are public.

c403 documentation built on Oct. 20, 2023, 3:01 p.m.