【发布时间】:2018-08-28 06:19:11
【问题描述】:
以下代码将绘制点和样条曲线(通过样条函数获得):
x <- 1:7
y <- c(2,1,4,2,5,1,2)
# plot the points
plot(x, y)
# plot the spline
lines(spline(x, y, n = 100, method = "natural"), col = 2)
我需要的是由spline(x, y, n = 100, method = "natural") 获得的函数本身,因此我可以在给定任何x 的情况下获得y 的值。我该怎么做?
我尝试了下面的代码,但它不起作用
f <- spline(x, y, n = 100, method = "natural")
f(7)
【问题讨论】:
标签: r