0

I need to collapse the values in B:

A      B
1      xyz
2      opi
1      abc

I need the below output:

A  B
1  xyz / abc
2  opi
iod
  • 7,412
  • 2
  • 17
  • 36
R perfect
  • 19
  • 1

2 Answers2

2

aggregate(your_data_frame[2], your_data_frame[1], paste, collapse = " / ")

RandomUser
  • 21
  • 1
0

tidyverse approach using dplyr:

library(dplyr)
x <- read.table(text = "A      B
1      xyz
2      opi
1      abc",header  =TRUE)

x %>% group_by(A) %>% summarise(B = paste(B, collapse = " / "))

## A tibble: 2 x 2
#      A B        
#  <int> <chr>    
#1     1 xyz / abc
#2     2 opi