[R] Fill a matrix with vectors of different lengths

From: Serguei Kaniovski <kaniovsk_at_wifo.ac.at>
Date: Mon 16 Oct 2006 - 08:27:52 GMT


how can I best fill a (fixed) matrix with vectors of varying lengths by column, setting the superfluous elements to zero? Here is my code:



	for (i in x) y<-y+c(rep(0,i),y)[1:l]


mat<-matrix(0, nrow=sum(v)+1, ncol=length(v)) for (i in 1:length(v)) mat[,i]=mat[,i]+binc(v[1:i])

the expression in the for-loop produces an error since mat[,i] and binc(v[1:i]) are of unequal lengths, except on the last iteration.

Thanks in advance,


Austrian Institute of Economic Research (WIFO)

Name: Serguei Kaniovski			P.O.Box 91
Tel.: +43-1-7982601-231			Arsenal Objekt 20
Fax:  +43-1-7989386			1103 Vienna, Austria
Mail: Serguei.Kaniovski@wifo.ac.at


R-help@stat.math.ethz.ch mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon Oct 16 18:35:02 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 16 Oct 2006 - 10:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.