Re: [R] Creating the right table from lapply list

2018-03-29 Thread Eric Berger
I like Don's answer which is clean and clear. A frequently useful alternative to lapply() is sapply(). Taking the sapply() route also avoids the need for do.call(). So a modified version of Don's code would be: ## example data output <- list(1:5, 1:7, 1:4) maxlen <- max( sapply(output, length) )

Re: [R] Creating the right table from lapply list

2018-03-28 Thread MacQueen, Don
Perhaps this toy example will help: ## example data output <- list(1:5, 1:7, 1:4) lens <- lapply(output, length) maxlen <- max(unlist(lens)) outputmod <- lapply(output, function(x, maxl) c(x, rep(NA, maxl-length(x))), maxl=maxlen) outputmat <- do.call(cbind, outputmod) write.csv(outputmat, na=''

Re: [R] Creating the right table from lapply list

2018-03-28 Thread Bert Gunter
If I understand correctly, this query is really about how to organize your data, not how to use R code to do it, though that may come later. Of course, the first question is why mess with Excel at all? But I shall assume you have good reason to get your data into Excel and do what you want to with