Skip to content
Prev 273793 / 398506 Next

Expand dataframe according to limits defined per row

Here's one way to do it with the plyr package:

library('plyr')
f <- function(df) with(df, data.frame(B = B, E = seq(C, D)))
ddply(d, 'A', f)

A corresponding solution with the data.table package would be

library('data.table')
dt <- data.table(d, key = 'A')
dt[, list(B, E = seq(C, D)), by = 'A']

HTH,
Dennis
On Fri, Oct 7, 2011 at 7:02 AM, darkgaze <donaldngwe at gmail.com> wrote: