不同长度变量的插值

interpolation of variables with different lengths

我有两个 data.frames 一个带有花粉 (p1) 和另一个 SST (s1) 都针对 Depth。但是 STT data.frame 有两倍的样本,我(认为?)确实需要插入 SST 值以适应花粉深度。 我尝试了另一个问题中建议的代码,但我没有那么成功。

> s1
# A tibble: 295 x 2
   Depth   SST
   <dbl> <dbl>
 1  10.0  14.6
 2  15.0  15.3
 3  20.0  15.6
 4  25.0  15.7
 5  30.0  15.7
 6  35.0  16.1
 7  40.0  16.0
 8  45.0  16.0
 9  50.0  15.8
10  55.0  16.0
# ... with 285 more rows

> p1
# A tibble: 143 x 1
   Depth
   <dbl>
 1  20.0
 2  30.0
 3  40.0
 4  50.0
 5  60.0
 6  70.0
 7  75.0
 8  90.0
 9 100  
10 110  
# ... with 133 more rows

我试图复制一个可用的代码并查看其他一些答案...但是因为我没有经验,所以我得到了一个 NULL 结果!

谁能帮帮我,拜托!提前谢谢你!

尝试

fit <- with(s1, smooth.spline(x = Depth, y = SST))

predict(fit, x=p1$Depth)

没有 dput 来加载你的小标题,由于我不使用它,我希望 data.frame 语法在这里有效。