[R] apply() question

Thomas Lumley tlumley at u.washington.edu
Thu Oct 16 16:06:16 CEST 2003


On Thu, 16 Oct 2003, Robin Hankin wrote:
>
> what I want is the equivalent of
>
> R> rbind(a[[1]],a[[2]],a[[3]],a[[4]],a[[5]])
>

Note that while do.call("rbind",a) is the natural solution it may in fact
be faster to create a matrix and use a loop to put things in it.

rval<-matrix(ncol=4, nrow=sum(sapply(a,nrow)))
i<-1
for(ai in a){
	r<-nrow(ai)
	rval[i+1:r,]<-ai
	i<- i+r
}


	-thomas




More information about the R-help mailing list