I have a dataframe like the below:
x <- tibble(id = c(1,1,1,2,2,2),
val = c(1,3,5,7,9,11)
)
I would like to group_by
each id
, then apply a list/vector of all the val
s in each group to every member of that group. The result would be a dataframe like that below.
x_out <- tibble(id = c(1,1,1,2,2,2),
val = c(1,3,5,7,9,11),
group_vals = list(c(1,3,5),c(1,3,5),c(1,3,5),
c(7,9,11),c(7,9,11),c(7,9,11))
)
How can I do this, since functions like summarize
only return a single value for the entire group?