Re: [R] merge numerous columns of unequal length

From: <markleeds_at_verizon.net>
Date: Mon, 05 May 2008 18:02:15 -0500 (CDT)


you can do below but there's no way of getting arounf having NAs in your final matrix.

d1<-as.matrix(rnorm(5))
d2<-as.matrix(rnorm(3))
d3<-as.matrix(rnorm(6))

templist <- list(d1,d2,d3)
maxnum <- max(sapply(templist,length))
print(maxnum)

temp <- lapply(templist,function(.mat) {

   if (nrow(.mat) < maxnum) {

      return(c(.mat,rep(NA,maxnum-nrow(.mat))))     } else {
      return(.mat)
    }
})

finalmat <- as.matrix(do.call(cbind,temp)) print(finalmat)

On Mon, May 5, 2008 at 6:46 PM, T.D.Rudolph wrote:

> I have numerous objects, each containing continuous data representing
> the
> same variable, movement rate, yet each having a different number of
> rows. e.g.
> d1<-as.matrix(rnorm(5))
> d2<-as.matrix(rnorm(3))
> d3<-as.matrix(rnorm(6))
>
> How can I merge these three columns side-by-side in order to create a
> table
> regardless of the difference in length? I wish to analyze the output
> in a
> spreadsheet format.
>
> Thanks!
> Tyler
> --
> View this message in context:
> http://www.nabble.com/merge-numerous-columns-of-unequal-length-tp17071464p17071464.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 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 05 May 2008 - 23:06:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 06 May 2008 - 00:30:33 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.

list of date sections of archive