请输入R以下结构:
g <- c(0.00125277273229879, 0.00126154615176554, 0.0012703959424814,
0.00127932294600281, 0.00128832795839672, 0.00129741176435766,
0.00130657513720778, 0.00131581896967928, 0.00132514399529097,
0.00133455111246124, 0.00134404117411893, 0.0013536149592724,
0.00136327342888814, 0.00137301739609167, 0.00138284774792897,
0.00139276542262179, 0.00140277127309897, 0.00141286625464083,
0.00142305128272433, 0.0508421359805228, 0.00186998245686827,
0.00188362983020243, 0.00189739567535365, 0.00191128104995371,
0.00192528723908206, 0.00193941540840815, 0.00195366674065997,
0.00196804251523079, 0.00198254393190719, 0.0019971722359653,
0.00201192874091554, 0.00202681464654449, 0.0020418313232245,
0.00205698005034884, 0.00207226214711413, 0.002087678932717,
0.00210323179458836, 0.00211892205192484, 0.00213475116039167,
-0.114451596942742, 0.00120694924932032, 0.00121602907494663,
0.00122519601872553, 0.00123445103025114, 0.00124379508186234,
0.00125322929373903, 0.00126275455292721, 0.00127237205352726,
0.00128208273376092, 0.00129188771380808)
gx <- c(122.05, 122.1, 122.15, 122.2, 122.25, 122.3, 122.35, 122.4,
122.45, 122.5, 122.55, 122.6, 122.65, 122.7, 122.75, 122.8, 122.85,
122.9, 122.95, 123, 123.05, 123.1, 123.15, 123.2, 123.25, 123.3,
123.35, 123.4, 123.45, 123.5, 123.55, 123.6, 123.65, 123.7, 123.75,
123.8, 123.85, 123.9, 123.95, 124, 124.05, 124.1, 124.15, 124.2,
124.25, 124.3, 124.35, 124.4, 124.45, 124.5)
我想找到一个插入g ~ gx
的函数,但它应该有一些特殊的功能:
作为第二个功能的示例,请考虑
y <- function(x) {
x ^ 2
}
是否有任何方法将y
与R合并,可以返回(x ^ 3) / 3
而不是在积分极值之间评估的数值?
谢谢,
答案 0 :(得分:1)
如果可以进行线性插值,则approxfun
将返回计算插值的函数。您可能更愿意使用lm
,然后predict
对lm
返回的对象执行操作。
而且,正如JG在评论中指出的那样,如果你的数据集有“尖锐的曲线”或者没有密集包装,splinefun
可能会给你一个更好的拟合函数。