[R] how to calculate derivative

Ravi Varadhan rvaradhan at jhmi.edu
Tue Nov 23 04:49:15 CET 2010


Here is a simple approach:

data <- read.table("test-data.txt")

deriv <- diff(data$V2) / diff(data$V1)

times <- (data$V1[-1] + data$V1[-3545])/2

plot(times, deriv, type="l")

Another approach is to smooth the original data and then obtain derivatives from the smooth

Ravi.

____________________________________________________________________

Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


----- Original Message -----
From: Yogesh Tiwari <yogesh.mpi at googlemail.com>
Date: Monday, November 22, 2010 5:14 pm
Subject: [R] how to calculate derivative
To: r-help <r-help at stat.math.ethz.ch>


> Dear R Users,
>  
>  I have trend of two time series of CO2 each 10  years of data. One is
>  varying
>  weekly and another is bi-weekly. I want to calculate Growth rate ppmv 
> / year
>  of these CO2 trends. Therefore I want to calculate  time derivative 
> ppmv /
>  year.
>  
>  How to do it in R?
>  
>  Here I attached example data file, I would appreciate if any one 
> kindly can
>  help on it.
>  
>  Thanks,
>  
>  Regards,
>  Yogesh 
> ______________________________________________
>  R-help at r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list