Skip to content
Prev 75975 / 398502 Next

vectors of different length in a matrix

On 8/22/2005 8:45 AM, Marten Winter wrote:
Filling with NA's is the hard part; R normally likes to recycle vectors 
that are too short.

Here's one way, probably not the best:

x <- matrix(NA, 3, max(length(a), length(b), length(c)))
x[1,seq(along=a)] <- a
x[2,seq(along=b)] <- b
x[3,seq(along=c)] <- c

Another way to do it would be to extend all the vectors to the same 
length by appending NAs, then using rbind.

Duncan Murdoch