[R] unlisting dplyr do output

Nathan Pace n.l.pace at utah.edu
Wed Jun 24 22:39:55 CEST 2015


I used the dplyr do function to apply a kernel regression smoother to a 3
column data table (grouping index, x, y) with about 7 M rows and 45000
groups.

This runs quickly, about 1-2 minutes.

It creates an data table (44,326 by 2) - grouping index, kernel smoothing
output.

The kernel smoothing output is a list of two element lists (x, smoothed y).

I used a for loop to unlist this into a data table.

  for (i in 1:nrow(do object)) {
df <- bind_rows(list(df,
                                  data.frame(grouping index = do object[i],
                                             x = do object[[i]]$x,
                                             y = do object[[i]]$smoothed
y)))
}


This takes about 100 minutes.

Any guidance for a faster (more elegant?) solution will be appreciated.

Nathan 



More information about the R-help mailing list