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
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