R dataframe: Transfrom values on multiple rows into list

I want to transform this:

library(tibble)
(
  tribble(
    ~id, ~value,
## -----|--------| 
     1,   "qwer",
     1,   "asdf",
     2,   "uiop",
     3,   "zxcv",
     3,   "qwer",
     3,   "uiop" )
) -> input

into this:

(
  tribble(
    ~id,          ~values,
## -----|------------------------------| 
     1,   list("qwer", "asdf"),
     2,   list("uiop"),
     3,   list("zxcv", "qwer", "uiop"))
) -> output

Please note that the number of disinct values is not known...



Read more here: https://stackoverflow.com/questions/66274243/r-dataframe-transfrom-values-on-multiple-rows-into-list

Content Attribution

This content was originally published by pietrodito at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: