2

I am trying to get a data frame from the output of approx(t,y, n=120) below. My intent is for the input values returned to be in increments of 0.25; for instance, 0, 0.25, 0.5, 0.75, ... so I've set n = 120.

However, the data frame I get doesn't return those input values.

t <- c(0, 0.5, 2, 5, 10, 30)
z <- c(1, 0.9869, .9478, 0.8668, .7438, .3945)
data.frame(approx(t, z, n = 120))

I appreciate any assistance in this matter.

Chris A.
  • 369
  • 2
  • 14
  • 2
    You should share what results you get, such as errors or unexpected results. –  Sep 24 '18 at 16:11

1 Answers1

2

There are 121, not 120, points from 0 to 30 inclusive in steps of 0.25

length(seq(0, 30, 0.25))
## [1] 121

so use this:

approx(t, z, n = 121)

Another approach is:

approx(t, z, xout = seq(min(t), max(t), 0.25))
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
  • Thank you for providing two approaches to the problem. The second approach is more intuitive for me, but the first approach makes sense in hindsight now - I did not mentally account for the inclusion of 0. – Chris A. Sep 24 '18 at 16:23