2

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?

KjetilH
  • 47
  • 4
  • 1
    The values you've given (`c(1,100,500,1000)`) all seem to be much less than the minimum x value used to generate the function, so this would be the expected behaviour. Can you edit the question to indicate what you're aiming to achieve? – Miff Mar 03 '23 at 09:26
  • You are of course completely right. I was using x-values that were too low. – KjetilH Mar 03 '23 at 09:45
  • @KjetilH instead of putting the solution as an edit, can you put it as answer and accept it? This will remove this question from the "Unanswered" category – bretauv Mar 14 '23 at 09:47
  • @bretauv Yes. I have done so now. – KjetilH Mar 14 '23 at 20:44

1 Answers1

0

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.

KjetilH
  • 47
  • 4