I have something like this:
| var1 | var2 | var3 | var4 | 
| a | x | Red | 1 | 
| a | x | Green | 2 | 
| b | y | Red | 3 | 
| b | y | Green | 4 | 
This is a simplified version of my data, most of them only have 1 unique var1 and var2, which I intend to use for merging data. But from some variables, there are different types of Var3, which separates them.
What I want to achieve is to add up var4 if var1 and var2 are the same, and drop every var3 != Red.
So the effect I want is:
| var1 | var2 | var3 | var4 | 
| a | x | Red | 3 | 
| b | y | Red | 7 | 
I got a feeling that I should use for loop but not sure where to start.
Can anyone help please?
Thank you sooooo much!!!

0 Response to Need some help dealing with duplicates
Post a Comment