rdataframefunctionfunction-approximation

R: approxfun() only returns first observation of y


EDIT: The solution is simple. As Miff points out, I'm using values of x that are too low. I suppose I might leave the question up for the next person who makes this mistake.

I'm attempting to use the approxfun() to approximates a function for a simple xy-matrix. The data frame is called supply1, and contains 363 rows:

> head(supply1)
         x        y
1 23367.20 92.43423
2 23603.24 93.36791
3 23841.65 94.31102
4 24082.48 95.26366
5 24325.73 96.22592
6 24571.45 97.19789

When I use approxfun() on this data, the function produces a string of values containing only the initial observation of y: 92.43423.

> fun_supply <- approxfun(supply1$x, supply1$y, rule = 2)

> fun_supply(c(1,100,500,1000))

[1] 92.43423 92.43423 92.43423 92.43423

I expected a string of increasing y-values. Any ideas as to what I'm doing wrong here?


Solution

  • The solution is simple. As Miff points out in a comment, I'm using values of x that are too low. Simple mistake on my end.