I have a list of length 30,000 with data frames in it that have a x and y column. The data frame is sparse, so not each value of x exists. All x values are between 1 and 200.
I want to convert this list to a single data frame which has for each possible x value a column and each row should represent all y values of a list entry (if a x value does not exist, the entry should be 0). I have a solution which works (see below) but it's very, very slow and I think there must be a faster (and probably also more elegant way) to do so.
My current solution (which is slow) is:
dat <- matrix(numeric(0), 30000, 200)
for(i in seq(along=whaledatas)) {
for(j in row.names(whaledatas[[i]]))
dat[i, whaledatas[[i]][j,"x"]] <- whaledatas[[i]][j,"y"]
}
dfData <- data.frame(dat, files$label)
dfData[is.na(dfData)] <- 0