[R] Convert components of a list to separate columns in a data frame or matrix XXXX

Rui Barradas ruipbarradas at sapo.pt
Sun Jan 8 20:31:39 CET 2012


Hello,

I believe this solves your problem


fun <- function(x){
	f <- function(x, n){
		if(length(x) < n) x <- c(x, rep(NA, n-length(x)))
		return(x)
	}
	lapply(x, f, max(unlist(lapply(x, length))))
}

fun(result)         # the 'result' list above

list2 <- list(x=1:3, y=1:5, z="abc")
fun(list2)


The function returns a list, then it can be made a matrix, a data.frame or
whatever.

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Convert-components-of-a-list-to-separate-columns-in-a-data-frame-or-matrix-XXXX-tp4275790p4276510.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list