Try this. You can bind data by rows and summarise using toString()
in order to arrange values. Finally, you can clean the data to get the expected order using mutate()
, gsub()
and paste0()
:
library(dplyr)
#Code
new <- df1 %>% bind_rows(df2) %>%
group_by(COL1) %>%
summarise(total=toString(total)) %>%
mutate(total=gsub(', ','(',total),
total=paste0(total,')'))
Output:
# A tibble: 6 x 2
COL1 total
<chr> <chr>
1 A 23(2)
2 B 76(9)
3 C 89(1)
4 D 29(21)
5 E 9(5)
6 F 2(1)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…