这应该不难,但我搜索了很多,到目前为止还没有找到解决方案......
我正在处理一些分散的数据
y = f(x1,x2,x3,..., xn)
我想创建一个查找函数,它为我提供了确切的已知值y
当输入向量时x
它在数据集中,但当向量时线性插值x
不在数据集中。
基本上喜欢approx()
,但对于更高的维数。
为了简化试用,这里有一些数据:
y<-rnorm(27)
x1<-seq(1,3,1)
x2<-seq(10,30,10)
x3<-seq(100,300,100)
df<-expand.grid(x1,x2,x3)
df<-cbind(y,df)
names(df)<-c("y","x1","x2","x3")
# Task is to create a function like
# fun(x1,x2,x3) --> interpolated y
# expected output example:
# fun(1,10,100) --> -0.89691454
# fun(1.5,10,100) --> -0.3560327