如何估计 R 中图形线上的点的坐标?

the*_*ist 4 r lines points coordinates

假设我有数据:

x <- c(1900,1930,1944,1950,1970,1980,1983,1984)
y <- c(100,300,500,1500,2500,3500,4330,6703)
Run Code Online (Sandbox Code Playgroud)

然后,我绘制这些数据并在已知的 x 和 y 坐标之间添加一个折线图:

plot(x,y)
lines(x,y)
Run Code Online (Sandbox Code Playgroud)

有没有办法预测沿图形线的未知点的坐标?

pic*_*ick 6

您可以使用approxfun

f <- approxfun(x, y=y)

f(seq(1900, 2000, length.out = 10))
# [1]  100.0000  174.0741  248.1481  347.6190  574.0741 1777.7778 2333.3333
# [8] 3277.7778        NA        NA
Run Code Online (Sandbox Code Playgroud)

注意 NA,当序列超出插值点范围时(approxfun 有左和右选项)。