here, I want to group all the values in column cont_name
based on column ticker
.
For Example below dataset:-
I want the output to be like:-
As you can see the cont_name
column's values have been appended by grouping on ticker
here, I want to group all the values in column cont_name
based on column ticker
.
For Example below dataset:-
I want the output to be like:-
As you can see the cont_name
column's values have been appended by grouping on ticker
I agree with dario in the comments, but it's easy to solve with group_by
and paste
:
library(tidyverse)
cont <- tibble(
ticker = c(rep('000001-SHE', 6), '000002-SHE', rep('000046-SHE', 2)),
cont_name = c('Bribery and Corruption', 'Business Ethics', 'Corporate Governance', 'Quality and Safety', 'Social Impacts of Products', 'Carbon Impacts of Products', 'Quality and Safety', 'Business Ethics', 'Labour Relations')
)
cont %>%
group_by(ticker) %>%
summarize(cont_name = paste(cont_name, collapse = ','))