I would rotate the data into a long format, join the two data sets, do the calculation and then rotate back to the wide format.
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(tidyr)
DF1 <- data.frame(ID = c(101,102,103), elevation = c(-10, 2000, 1400),
temp1 = c(2,3.1,4.0), temp2 = c(3.5, 3.0, 2.8),
temp3 = c(2.2, 5.1, 4.1))
DF2 <- data.frame(ID = c(101,102,103), elevation = c(350, 2206, 1450),
temp1 = c(1.8, 2.1, 1.0), temp2 = c(3.0, 4.0, 2.3),
temp3 = c(2.9, 4.1, 6.1))
DF1_lng <- DF1 %>% gather(key = TempSeq, value = Value, temp1:temp3)
DF2_lng <- DF2 %>% gather(key = TempSeq, value = Value, temp1:temp3)
DFjoin <- inner_join(DF1_lng, DF2_lng, by = c("ID", "TempSeq"), suffix = c("_1", "_2"))
DFjoin <- DFjoin %>% mutate(Value2adj = ifelse(abs(elevation_1 - elevation_2) >= 100,
Value_2 + (elevation_2 - elevation_1) * 6.5/1000, Value_2))
DFjoin
#> ID elevation_1 TempSeq Value_1 elevation_2 Value_2 Value2adj
#> 1 101 -10 temp1 2.0 350 1.8 4.140
#> 2 102 2000 temp1 3.1 2206 2.1 3.439
#> 3 103 1400 temp1 4.0 1450 1.0 1.000
#> 4 101 -10 temp2 3.5 350 3.0 5.340
#> 5 102 2000 temp2 3.0 2206 4.0 5.339
#> 6 103 1400 temp2 2.8 1450 2.3 2.300
#> 7 101 -10 temp3 2.2 350 2.9 5.240
#> 8 102 2000 temp3 5.1 2206 4.1 5.439
#> 9 103 1400 temp3 4.1 1450 6.1 6.100
DF2adj <- DFjoin %>% select(ID, elevation = elevation_2, TempSeq, Value2adj) %>%
spread(key = TempSeq, value = Value2adj)
DF2adj
#> ID elevation temp1 temp2 temp3
#> 1 101 350 4.140 5.340 5.240
#> 2 102 2206 3.439 5.339 5.439
#> 3 103 1450 1.000 2.300 6.100
Created on 2019-05-14 by the reprex package (v0.2.1)