Consider a list of vectors with different lenghts, for example lV defined as
set.seed(123)
v1 = rnorm(n = 5)
v2 = rnorm(n = 4)
v3 = rnorm(n = 3)
lV = list(v1, v2, v3)
How can I bind the vectors in a compact manner similarly to
do.call("cbind", lV)
but obtaining the output of
cbind(v1[3 : 5], v2[2 : 4], v3)
? Preferably without using slow functions.
If it wasn't clear, I am trying to retain the last n elements of each vector, where
n = min(sapply(X = lV, FUN = length))
print(n)
A short code option