Challenge - 5 Problems
Vector Function Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:00remaining
What is the output of this R code using length()?
Consider the vector
v <- c(3, 7, 2, 9, 4). What does length(v) return?R Programming
v <- c(3, 7, 2, 9, 4) length(v)
Attempts:
2 left
💡 Hint
The length() function returns how many elements are in the vector.
✗ Incorrect
The vector
v has 5 numbers, so length(v) returns 5.❓ Predict Output
intermediate1:00remaining
What is the sum of elements in this vector?
Given
nums <- c(10, 20, 30, 40), what does sum(nums) return?R Programming
nums <- c(10, 20, 30, 40) sum(nums)
Attempts:
2 left
💡 Hint
sum() adds all numbers in the vector.
✗ Incorrect
Adding 10 + 20 + 30 + 40 equals 100, so sum(nums) returns 100.
❓ Predict Output
advanced1:30remaining
What is the mean of this vector with NA values?
Given
data <- c(5, NA, 15, 20), what does mean(data, na.rm = TRUE) return?R Programming
data <- c(5, NA, 15, 20) mean(data, na.rm = TRUE)
Attempts:
2 left
💡 Hint
na.rm = TRUE tells mean() to ignore NA values.
✗ Incorrect
Ignoring NA, the mean is (5 + 15 + 20) / 3 = 13.33333.
❓ Predict Output
advanced1:30remaining
What error does this code produce?
What happens when you run
sum(c(1, 2, '3')) in R?R Programming
sum(c(1, 2, '3'))
Attempts:
2 left
💡 Hint
sum() expects numeric values, but '3' is a character here.
✗ Incorrect
The vector mixes numbers and a character, so sum() cannot add them and throws a type error.
🧠 Conceptual
expert2:00remaining
How many elements are in the vector after this operation?
If
v <- c(1, 2, 3, 4, 5) and then v <- v[-c(2, 4)] is run, what is length(v)?R Programming
v <- c(1, 2, 3, 4, 5) v <- v[-c(2, 4)] length(v)
Attempts:
2 left
💡 Hint
Removing elements 2 and 4 means those positions are gone from the vector.
✗ Incorrect
Removing elements at positions 2 and 4 leaves elements 1, 3, and 5, so length is 3.