Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ddply summarise string operation

Tags:

r

plyr

I am using ddply right now. It's very easy to deal with numbers. Such as take the mean or standard deviation of the subgroup.

But I have difficulty dealing with strings. I would like to combine the strings in the same column in each subgroup, but I could not do it. I tried cbind paste, etc. Anyone can offer some help?

like image 437
user1652926 Avatar asked Sep 06 '12 20:09

user1652926


1 Answers

Add collapse="" to your paste statement

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
like image 196
Dason Avatar answered Sep 21 '22 15:09

Dason