Re: [R] converting a list to a data.frame

From: Patrick Connolly <p_connolly_at_ihug.co.nz>
Date: Wed 04 Apr 2007 - 05:10:27 GMT

On Tue, 03-Apr-2007 at 01:55PM +0200, Dimitris Rizopoulos wrote:

|> try something like this:
|>
|> lis <- list(c(1,2,4), c(4,5,2,1), c(3,4,6,3), c(3,1,76,4,2))
|> ##########
|> n.max <- max(sapply(lis, length))
|> val <- NA # what to fill in
|> fill <- function(x) c(x, rep(val, n.max - length(x)))
|> as.data.frame(do.call(rbind, lapply(lis, fill)))

I think that should be cbind, not rbind.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___    Patrick Connolly   
 {~._.~}          		 Great minds discuss ideas    
 _( Y )_  	  	        Middle minds discuss events 
(:_~*~_:) 	       		 Small minds discuss people  
 (_)-(_)  	                           ..... Anon
	  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

______________________________________________
R-help@stat.math.ethz.ch 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 Wed Apr 04 15:13:08 2007

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 Wed 04 Apr 2007 - 05:31:00 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.