I have one df1 and I want to merge certain rows of specific columns based on the names of another column
Asked
Active
Viewed 50 times
1 Answers
1
An option is aggregate by specifying a formula with the rhs specifying the grouping column ('Name') and . for all the others ('Likes', 'How many hrs spend liking') and paste them together
aggregate(. ~ Name, df1, FUN = toString)
akrun
- 789,025
- 32
- 460
- 575
-
1If you use the vector function `c` as your FUN you can keep the class of each column. – Daniel O Mar 28 '21 at 11:41
-
@DanielO It would return a `list` column. Not sure if the OP wants that – akrun Mar 28 '21 at 11:42
-
Thank you for the suggestion! What do you mean by rhs? So you mean it would be: df2 – mk894 Mar 29 '21 at 01:03
-
@mk894 It means each of the columns are individually aggregated by Name with that single command. – akrun Mar 29 '21 at 04:58