Recall & Review
beginner
What is vector recycling behavior in R?
Vector recycling is when R repeats elements of a shorter vector to match the length of a longer vector during operations.
Click to reveal answer
intermediate
What happens if the length of the longer vector is not a multiple of the shorter vector's length during recycling?
R gives a warning because the shorter vector cannot be evenly recycled to match the longer vector's length.
Click to reveal answer
beginner
Example: What is the result of c(1, 2, 3) + c(10, 20)?
The shorter vector c(10, 20) is recycled to c(10, 20, 10). The result is c(11, 22, 13).
Click to reveal answer
beginner
Why is vector recycling useful in R?
It allows element-wise operations between vectors of different lengths without manually repeating elements.
Click to reveal answer
intermediate
How can you avoid unexpected results from vector recycling?
Make sure vector lengths are compatible or explicitly repeat elements using functions like rep() before operations.
Click to reveal answer
What does R do when adding vectors of different lengths?
✗ Incorrect
R recycles the shorter vector's elements to match the length of the longer vector during operations.
What warning does R give if the longer vector's length is not a multiple of the shorter vector's length?
✗ Incorrect
R warns that the shorter vector's length does not evenly divide the longer vector's length during recycling.
What is the result of c(4, 5) + c(1, 2, 3, 4)?
✗ Incorrect
The shorter vector c(4, 5) is recycled as c(4, 5, 4, 5). Since 4 is not a multiple of 2, R completes the operation with a warning.
Which function can you use to manually repeat elements of a vector in R?
✗ Incorrect
The rep() function repeats elements of a vector as specified.
Vector recycling is most similar to which real-life situation?
✗ Incorrect
Recycling repeats a shorter vector like repeating a short playlist to fill a longer time.
Explain vector recycling behavior in R with an example.
Think about how R handles adding vectors like c(1,2,3) and c(10,20).
You got /3 concepts.
How can you prevent unexpected results when working with vector recycling?
Consider what happens if vector lengths don't match nicely.
You got /3 concepts.