0

I have a CSV file where there are 4 columns. I would like to get answer by adding the 4th column values where the 3rd column values are same.

The data that i have looks like this:

Now i want to aggregate the above data like this:

Anyone can help me with your ideas!

1 Answers1

0

Using aggregate would do the trick here. Below I'm summing the value variable using id as the group (notice ids 6 and 10 are repeating).

df <- data.frame(id = c(1,2,3,4,5,6,6,7,8,9,10,10),
                 value = c(9,5,6,8,4,3,2,5,3,5,1,2))

df_sum <- aggregate(value ~ id, data=df, FUN=sum)
Rob Marty
  • 378
  • 1
  • 9