I'm not sure which function to use to do the following:
library(data.table)
dt = data.table(a = 1:4, b = 1:2)
dt[, rep(a[1], 3), by = b]
# b V1
#1: 1 1
#2: 1 1
#3: 1 1
#4: 2 2
#5: 2 2
#6: 2 2
Both summarise and mutate are unhappy with this length:
library(dplyr)
df = data.frame(a = 1:4, b = 1:2)
df %.% group_by(b) %.% summarise(rep(a[1], 3))
#Error: expecting a single value
df %.% group_by(b) %.% mutate(rep(a[1], 3))
#Error: incompatible size (3), expecting 2 (the group size) or 1
dplyrcode with adata.tableworks and withplyryou can do that too with adata.frame. - dickoadplyr- I don't really see the point of using it with adata.table); sounds like a bug insummarisethen - eddidf %>% group_by(b) %>% slice(rep(1, 3))works fine. For rowwise operations, where each row returns an arbitrary number of values, you can use thedf %>% mutate(new = map(old, f)) %>% unnest()idiom. - Axeman