I have an 'Exp
' data set which looks like this:
Locals Res Ind
1 112 7.865 4.248
2 113 4.248 5.666
3 114 5.666 2.444
4 115 2.444 7.865
5 116 7.865 4.248
6 117 4.248 6.983
7 118 5.666 3.867
8 119 2.444 2.987
And I have another data set called 'Com' as below:
113 112 113
112 114 119
116 118 119
118 118 119
117 117 119
117 117 119
Based on the value in the 'Com
' data set, I have pulled a corresponding value as part of the 'Res
' and 'Ind
' matrix
.
For eg - The first value in the Com
data set is 113
so in the Res matrix
the first value will be 4.248
- because the corresponding value in Exp's first column of 113
is 4.248
. Such that the 'Res
' matrix
looks something like this
4.248 7.865 4.248
7.865 5.666 2.444
7.865 5.666 2.444
5.666 5.666 2.444
4.248 4.248 2.444
4.248 4.248 2.444
Now based on the above 'Res
' data set, I want to deduct the first row
by 2
and rest of the rows
by 5
. Then I want to add up the values of the above data set based on the value of the Com
data set. For eg there are two 113
in the Com data set, the corresponding values in the Res
data set is (4.248 - 2) + (4.248 - 2)
. So it is equal to 4.496
. The Output table should look like something below:
Locals Dam
112 8.73
113 4.496
114 0.666
115 0
116 2.865
117 -3.008
118 1.998
119 -12.78
Can anybody please suggest a easy way to do this on R. If this is done on a list of data then what is the best way
Thanks in advance