Although I think Ricardo proposed a nice solution, a similar action would also work by applying a function to the list of vectors that you want to link. You can also specify the character to fill.
test <- list(v1,v2) maxlen <- max(sapply(test,length)) fillchar <- 0 do.call(rbind,lapply(test, function(x) c(x, rep(fillchar, maxlen - length(x) ) )))
Or avoid all the madness of do.call(rbind :
t(sapply(test, function(x) c(x, rep(fillchar, maxlen - length(x))))) # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] #[1,] 1 2 3 4 8 5 3 11 #[2,] 9 5 2 0 0 0 0 0
source share