I have a large dataframe and I need to summarize based on 3 columns (source, source_detail, information) and values in column year will be put into list, like in Table 2.
My first code is
data %>% group_by(source, source_detail, information) %>% summarise(list_year = unique(year))
but it returns view like in Table 1 below,
source | source_detail | information | list_year |
---|---|---|---|
AA | AA-11 | Number of women | 2019 |
AA | AA-11 | Number of women | 2020 |
AA | AA-22 | Number of men | 2018 |
AA | AA-22 | Number of men | 2019 |
AA | AA-22 | Number of men | 2020 |
BB | BB-33 | Percentage of women | 2012 |
BB | BB-33 | Percentage of women | 2017 |
BB | BB-33 | Percentage of women | 2022 |
BB | BB-44 | Percentage of men | 2017 |
BB | BB-44 | Percentage of men | 2022 |
while I need output like in Table 2 below
source | source_detail | information | list_year |
---|---|---|---|
AA | AA-11 | Number of women | 2019, 2020 |
AA | AA-22 | Number of men | 2018, 2019, 2020 |
BB | BB-33 | Percentage of women | 2012, 2017, 2022 |
BB | BB-44 | Percentage of men | 2017, 2022 |
Is it possible to do that in R?