r - joining strings in a table according to values in another column -


this question has answer here:

i got table this:

id     words 1     school. 2     hate school. 3     cakes. 1     cats. 

here's want do, joining strings in each row according id.

id    words 1    school. cats. 2    hate school. 3    cakes. 

is there package in r?

we can paste 'words' grouped 'id'. can done of group operations. 1 way data.table. convert 'data.frame' 'data.table' (setdt(df1)) , operation mentioned above.

# install.packages(c("data.table"), dependencies = true) library(data.table) setdt(df1)[, list(words = paste(words, collapse=' ')), = id] 

a base r operation use aggregate

aggregate(words~id, df1, fun= paste, collape=' ') 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -