Mingwei Min <mm809 <at> cam.ac.uk> writes:
> 
> Hi all,
> 
> I am trying to calculating derivatives for vectors using R. I have a
> numerical vector, which is in time series manner and contains "NA"s. I
> want to know the changing rate throughout the whole time range. I am
> wondering if there is function in R can do this. In R references I
> only found functions for calculating derivatives of expressions.
> 
> For example, vectors like this
> x<-c(0.997549748, 0.98039798, 0.963097713, 0.930576181, 0.907484407,
> 0.875705376, 0.826477576, NA, 0.772794773)
> 
> Thanks in advance.
> 
> Mingwei
> 

First you have to decide how to interpolate the data points, e.g. through a
polynomial fit (of degree 2,3,...), some Newton or Lagrangian interpolation,
spline fitting (see "splinefun()"), etc.

Then you can differentiate this fitted function, e.g. directly if it is a
polynomial or numerically (see "numderiv::grad()"). Most of these functions
just skip any "NA" values.

--Hans Werner

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to