Sum of all the rows in R without duplicates
I have a large data frame. I need to find the sum of all the rows of a
particular column but with duplicate items counted only once. For example,
Consider the following data frame:
z = data.frame(id = c(16249, 16249, 16250, 16251), value = c(1, 1, 2, 3))
   id     value
1 16249     1
2 16249     1
3 16250     2
4 16251     3
I need to find the sum of all the rows for the column "value" but with
duplicate "id" counted only once. So, in the above example, the answer
should be: 1+2+3 = 6 (corresponding to id 16249, 16250 and 16251).
Thanks!
 
No comments:
Post a Comment