I have something that looks like this:
Group1 <- list(Date=c("a","b","c"), Name=c("a2","b2"), Age=c("a3","b3","c3","d3"))
Group2 <- list(Date=c("a","b","c"), Name=c("a2","b2","b3"), Age=c("a3","b3","c3","d3"))
Group3 <- list(Date=c("a","b","c"), Name=c("a2","b2"), Age=c("a3","b3"))
all <- list(Group1,Group2,Group3)
all
What I need is to add NAs so that each list of Dates, Names, and Ages are equal length. I then need to convert this to a data frame.
I am stuck with how to add the NAs since I have lists within lists. I will have over 1,000 "Groups" with lists of data in them (always the same Date, Name, Age categories, so this length doesn't change). The longest list within these Groups should always be 4 for the current example, so anything less should have NAs. I've seen a code like this, which is close but does not work for lists within lists:
## Compute maximum length
max.length <- max(sapply(all, length))
## Add NA values to list elements
l <- lapply(all, function(v) { c(v, rep(NA, max.length-length(v)))})
Is there something similar I can do for my current data set?