How to automatically interpolate values for one data frame based on another lookup table/data frame?
问题 I have one data frame and one look up table. What I want is to compare df_dat$value with df_lookup$threshold . If the value falls into threshold range, then create a new column transfer in df_dat so that its values are linearly interpolated from the transfer column in df_lookup library(dplyr) df_lookup <- tribble( ~threshold, ~transfer, 0, 0, 100, 15, 200, 35 ) df_lookup #> # A tibble: 3 x 2 #> threshold transfer #> <dbl> <dbl> #> 1 0 0 #> 2 100 15 #> 3 200 35 df_dat <- tribble( ~date, ~value