I am trying to interpolate the exceedance probability between 2 time series, the time is not important here.
data1<-c(10,11,12,13,14,15)
data2<-c(20,21,22,23,24,25)
x<-c(1,2)
elevation<-c(10,11,20,24,25)
elevation<-data.table(elevation)
Where x[1] is the x parameter of data1 and data1 are the values at that location. Consider it mile 1 and mile 2. elevation is a sequence from the minimum of data1 to the maximum of data2.
I want to interpolate all the exceedance probabilities at mile 1.5. What I have tried is:
data1prob<-ecdf(data1)
data2prob<-ecdf(data2)
elevation[,prob:=1-as.numeric(approx(x = x, y =c(data1prob(elevation),data2prob(elevation)), xout = 1.5)[2])]
I receive the error:
Error in .approxfun(x, y, v, method, yleft, yright, f) : (list) object cannot be coerced to type 'double'
Which is from the call data1prob(elevation)
. I believe the elevation vector is called instead of the individual elevation values for each row.
I do not have any problem when I do elevation[,prob:=elevation-as.numeric(approx(x = x, y =c(5,6), xout = 1.5)[2])]
, but I do when I try elevation[,prob:=data1prob(elevation)]
for example.
Thanks for any input.