Complete the code to create a vector that repeats the elements of c(1, 2) to length 6.
rep(c(1, 2), [1] = 3)
The times argument tells rep() how many times to repeat the whole vector.
Complete the code to add two vectors with different lengths using recycling.
c(1, 2, 3, 4) + c(10, [1])
The shorter vector c(10, 20, 30) is recycled to match the length of the longer vector c(1, 2, 3, 4). Here, only 10, 20 are needed to fill the blank to make recycling happen.
Fix the error in the code that tries to add vectors of incompatible lengths.
c(1, 2, 3) + c(10, 20, 30, [1])
The second vector has length 4, which is not a multiple of 3, so recycling causes a warning. Removing the last element fixes the error.
Fill both blanks to create a vector that recycles elements of c(1, 2) to length 5 and then multiply by 2.
rep(c(1, 2), [1] = 5) * [2]
length.out = 5 makes the vector length 5 by recycling, and multiplying by 2 doubles each element.
Fill all three blanks to create a named vector with lengths of words longer than 3 letters.
lengths = { [1]: [2] for word in words if nchar(word) [3] 3 }This creates a named vector where names are words and values are their lengths, but only for words longer than 3 letters.