"Dennis Murphy" <djmuser at gmail.com> wrote in message
news:AANLkTinrAuFrh71J9WpNfZVg_8JAYACkw1e8CPn=cZ2g at mail.gmail.com...
Hi:
The essential problem is that after you append items, the result is a list
with possibly unequal lengths. Trying to convert that into a data frame by
the 'usual' methods (do.call(rbind, ...) or ldply() in plyr) didn't work
(as
anticipated). One approach is to initialize a maximum size matrix with NAs
and then replace the NAs by the contents of each component of the list.
The
following function is far from elegant, but the idea is to output a data
frame by 'NA filling' the shorter vectors in the list and doing the
equivalent of do.call(rbind, list).
listNAfill <- function(l) {
# input argument l is a list with numeric component vectors
lengths <- sapply(l, length)
m <- matrix(NA, nrow = length(l), ncol = max(lengths))
for(i in seq_len(length(l))) m[i, ] <- replace(m[i, ],
1:lengths[i],
l[[i]])
as.data.frame(m)
}