-1

I have data as follow.

1 b c 10
1 b c 30
2 c a 20

then I want to transform the data as below.

1 b c 10,30
2 c a 20

How to achieve my goal using R?

sclee1
  • 1,095
  • 1
  • 15
  • 36

1 Answers1

0

We can use dplyr

library(dplyr)
df1 %>%
   group_by_(.dots = names(df1)[1:3]) %>%
   summarise(col4 = toString(col4))
#   col1  col2  col3   col4
#   <int> <chr> <chr>  <chr>
#1     1     b     c 10, 30
#2     2     c     a     20
akrun
  • 874,273
  • 37
  • 540
  • 662