R中的插值数据

Cod*_*Guy 6 interpolation r gaussian

假设我在R中有一个3乘5的矩阵:

4  5  5  6  8
3  4  4  5  6
2  3  3  3  4
Run Code Online (Sandbox Code Playgroud)

我想在这些值之间进行插值以创建一个15乘25的矩阵.我还想指定插值是线性的,高斯的等等.我该怎么做?

例如,如果我有一个像这样的小矩阵

2 3
1 3
Run Code Online (Sandbox Code Playgroud)

我希望它变成3乘3,然后它可能看起来像

  2    2.5   3
  1.5  2.2   3
  1    2     3 
Run Code Online (Sandbox Code Playgroud)

Mat*_*erg 6

app <- function(x, n) approx(x, n=n)$y # Or whatever interpolation that you want

apply(t(apply(x, 1, function(x) app(x, nc))), 2, function(x) app(x, nr))
     [,1] [,2] [,3]
[1,]  2.0 2.50    3
[2,]  1.5 2.25    3
[3,]  1.0 2.00    3
Run Code Online (Sandbox Code Playgroud)