[R] converting a list to a data.frame

Patrick Connolly p_connolly at ihug.co.nz
Wed Apr 4 07:10:27 CEST 2007


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
	  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.



More information about the R-help mailing list