If I have two datasets, DF1 and DF2, with the same column names but different values for part of the columns (the temp columns in this example). My question is how to change the values in one dataset (DF2) according to the values of a column in another dataset (DF1). The example datasets are as follows.
DF1
ID elevation temp1 temp2 temp3
101 -10 2 3.5 2.2
102 2000 3.1 3.0 5.1
103 1400 4.0 2.8 4.1
...
DF2
ID elevation temp1 temp2 temp3
101 350 1.8 3.0 2.9
102 2206 2.1 4.0 4.1
103 1450 1.0 2.3 6.1
...
The two datasets have the similar dimension, and ID column, but different values for elevation, temp1, temp2, and temp3.
Assume that the values in DF1 are correct, while I need to scale up/down values of "temp1", "temp2", and "temp3" columns in DF2 according to differences between "elevation" column of the two datasets.
Specifically, if for each row, | DF1[i,]$elevation - DF2[i,]$elevation | < 100, then move to the next row (i.e. not consider for the case that elevation differences are less than 100), else, if for each row i, | DF1[i,]$elevation - DF2[i,]$elevation | >= 100, then there may be the two following conditions and scaling up/down processes accordingly.
(1) DF2[i,]$elevation < DF1[i,]$elevation, DF2[i,3:5] = DF2[i,3:5]- (6.5/1000)x(DF1[i,]$elevation - DF2[i,]$elevation)
(2) DF2[i,]$elevation > DF1[i,]$elevation, DF2[i,3:5]= DF2[i,3:5]+ (6.5/1000)x(DF2[i,]$elevation - DF1[i,]$elevation)
How to do this in a loop in R? Thanks.