0

I have a quick question regarding the R data.frame. My data.frame looks like this:

Category    Money

A            4
B            2
B            9
A            3
C            6         
A            2
C            4
B            8

My goal is to order this data frame such that every Category has the added up amount of money in their corresponding row. Like:

Category Money

A            9
B            19
C            10

I would really appreciate your help.

Lukas
  • 1
  • 1
    `aggregate(Money ~ Category, data = df, sum )` . Does this answer your question? [How to sum a variable by group](https://stackoverflow.com/questions/1660124/how-to-sum-a-variable-by-group) – maydin Nov 07 '20 at 11:40
  • Yes thanks a lot! You can I also add a new column that shows the mean amount of money per category? – Lukas Nov 07 '20 at 11:52
  • Just change `sum` by `mean` in the `aggregate` function. Then add the outputs with the previous one with `cbind()`. Alternatively, you can `mutate` new column by using the `dplyr`. Just check the link. There exists 16 different solutions in that question. – maydin Nov 07 '20 at 11:54

0 Answers0