-1

here, I want to group all the values in column cont_name based on column ticker .

For Example below dataset:-

enter image description here

I want the output to be like:-

enter image description here

As you can see the cont_name column's values have been appended by grouping on ticker

  • 4
    Please do not post photos of data or code! If you do, people who are willing to help you would have to type out all that text. Instead provide a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) P.S. Here is [a good overview on how to ask a good question](https://stackoverflow.com/help/how-to-ask) – dario Nov 03 '21 at 11:55
  • Yes noted! thanks for the suggestion! – Arihant Jain Nov 04 '21 at 04:58

1 Answers1

1

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 = ','))
Harrison Jones
  • 2,256
  • 5
  • 27
  • 34