I have this mapping table.
fli.1 = c(0, 700, 1500, 2000, 3500, 5600, 11000, 20000, 50000)
fli.2 = c(0, 200, 1000, 2900, 3000, 5500, 10000, 20000, 50000)
fli.3 = c(0, 600, 1200, 2500, 3900, 5000, 10000, 22000, 58000)
fli.4 = c(0, 300, 1000, 2000, 3000, 5000, 14000, 20000, 50000)
fli.5 = c(0, 500, 1000, 2000, 3500, 5000, 10000, 20000, 50000)
df <- data.frame(xt = c(rep("a",9),rep("b",9),rep("c",9)),
fli.1 = rep(fli.1,3),
fli.2 = rep(fli.2,3),
fli.3 = rep(fli.3,3),
fli.4 = rep(fli.4,3),
fli.5 = rep(fli.5,3));
and another dataframe which is.
d <- data.frame(xt=rep(c("a","b","c"),4),value = c(0, 2000, 5000, 6500, 40000, 60000, 400, 200, 40, 7899, 1000, 1500), fli = c("fli.1", "fli.1", "fli.4", "fli.5", "fli.2", "fli.2", "fli.5", "fli.1", "fli.2", "fli.2", "fli.3", "fli.4"));
Requirement is creating additional column to the right of dataframe d. such that.
d$value is 0,2000,5000,5000,20000, ... d$row is 1,13,24,6,17, ...
for e.g. first row in d is for (a, 0 ,fli.1) so look in fli.1 column and for a and the value should be less than or equal to 0. which would be (0,1)
another example for fifth row in d which is (b,40000,fli.2) so look in fli.2 column and for b and the value less than 40000. answer would be (20000,17).
this is just a representation with less data in actual the d dataframe is around 2million. Also the in the table df values are not repeated for a,b and c. it can be different. I am looking for a code from data.table package.