0

I have a data frame like this (as shown in the first image)

enter image description here

How to add the values of column 'Amount' based on the column 'Index'. For example, all the values of column 'Amount' having the common index should be added together and written in respective position in 'Sum'. It should look like this. (as shown in second image)

enter image description here

Jaap
  • 81,064
  • 34
  • 182
  • 193
  • Do not post your data as an image, please learn how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) – Jaap Jun 03 '17 at 13:30
  • 1
    With `library(dplyr); df %>% group_by(Index) %>% mutate(Sum = sum(Amount))` – Jaap Jun 03 '17 at 13:30
  • or with `library(data.table); setDT(df)[, Sum := sum(Amount), by = Index]` – Jaap Jun 03 '17 at 13:31

0 Answers0