Reputation: 573
I am using R Studio on Windows 8 machine. I am trying to interpolate a point between two points.
x1 = -159.9, y1 = 56.5,
x2 = -159.9, y2 = 56.3
I am using approx()
function in the following manner (reproducible)
approx(c(-159.9,-159.9), c(56.5,56.3), n = 3)
which gives me an error
Error in approx(c(-159.9, -159.9), c(56.5, 56.3), n = 3) :
need at least two non-NA values to interpolate
Its expecting two non-NA values, which I have provided.
The function is working flawlessly for other points. Just this is the problem. If you have come across any such error, please let me know how did you solve this?
Upvotes: 1
Views: 14416
Reputation: 148
The approx
function can't interpolate values where the x-coordinates are the same.
Hence, I would tackle this problem as follows:
approx
function.Upvotes: 3
Reputation: 3026
From the Details of ?approx()
:
The inputs can contain missing values which are deleted, so at least two complete (x, y) pairs are required (for method = "linear", one otherwise). If there are duplicated (tied) x values and ties is a function it is applied to the y values for each distinct x value.
Upvotes: 3