Ddply sum string operation

I am using ddplyright now. It is very easy to deal with numbers. For example, accept the mean or standard deviation of a subgroup.

But it's hard for me to deal with strings. I would like to combine rows in one column in each subgroup, but I could not do this. I tried cbind paste, etc. Can anybody help?

+5
source share
2 answers

Add collapse=""to folder operator

ddply(mtcars, .(carb), summarize, cyl_concatenated = paste(cyl, collapse = ""))
#  carb cyl_concatenated
#1    1          4664444
#2    2       8444888444
#3    3              888
#4    4       6686688888
#5    6                6
#6    8                8
+8
source

I see Dason has an approach. I would rather separate the individual things and suggest:

 ddply(mtcars, .(carb), summarize, cyl_list = list(as.character(cyl)))
#-----------
  carb                     cyl_list
1    1          4, 6, 6, 4, 4, 4, 4
2    2 8, 4, 4, 4, 8, 8, 8, 4, 4, 4
3    3                      8, 8, 8
4    4 6, 6, 8, 6, 6, 8, 8, 8, 8, 8
5    6                            6
6    8                            8

Dason collapse = ",", , , . list() .

+5

All Articles