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) )
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=''
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
3 matches
Mail list logo