I have 2 data frames like this:
zip c
1 2
2 5
3 3
4 4
and the other one:
x zip ch
1 1 2
2 2 1
3 1 4
what i want to do is to create another data frame (or add a column in the second one) in which the value has to be computed as (ch - c) when the two zip are the same. For instance, in the above example it would be like this:
x zip ch new
1 1 2 0
2 2 1 -4
3 1 4 2
I am currently doing it with a for loop, cycling over each item of the second data frame and checking for the correspondent one in the first data frame, but since my input data is quite huge, I am wondering whether R could do it faster.