Skip to content
Prev 275250 / 398506 Next

unfold list (variable number of columns) into a data frame

Hi:

Here's one approach:

# Function to process a list component into a data frame
ff <- function(x) {
     data.frame(time = x[1], partitioning_mode = x[2], workload = x[3],
                runtime = as.numeric(x[4:length(x)]) )
   }

# Apply it to each element of the list:
do.call(rbind, lapply(data, ff))

or equivalently, using the plyr package,

library('plyr')
ldply(data, ff)

# Example:
L <- list(c("1", "sharding", "query", "607", "85", "52", "79", "77",
"67", "98"),
          c("1", "sharding", "refresh", "2932", "2870", "2877", "2868"),
          c("1", "replication", "query", "2891", "2907", "2922", "2937"))
do.call(rbind, lapply(L, ff))
   time partitioning_mode workload runtime
1     1          sharding    query     607
2     1          sharding    query      85
3     1          sharding    query      52
4     1          sharding    query      79
5     1          sharding    query      77
6     1          sharding    query      67
7     1          sharding    query      98
8     1          sharding  refresh    2932
9     1          sharding  refresh    2870
10    1          sharding  refresh    2877
11    1          sharding  refresh    2868
12    1       replication    query    2891
13    1       replication    query    2907
14    1       replication    query    2922
15    1       replication    query    2937

HTH,
Dennis
On Sun, Oct 23, 2011 at 8:38 AM, Giovanni Azua <bravegag at gmail.com> wrote: