I would like to select the first observation be group and create a list column.
For example:
df <- structure(list(Grp = c("A", "A", "A", "B", "B"), col1 = c(1,
2, 3, 70, 80), col2 = c(4, 5, 6, 100, 110)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -5L))
I would like to create a column whose first element is c(1,4) and second element is c(70, 100).
I tried:
df %>% group_by(Grp) %>% mutate(L = list(slice(1)))
But got an error.