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: rvarad...@jhmi.edu ----- Original Message ----- From: Yogesh Tiwari <yogesh....@googlemail.com> Date: Monday, November 22, 2010 5:14 pm Subject: [R] how to calculate derivative To: r-help <r-h...@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@r-project.org mailing list > > PLEASE do read the posting guide > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ 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.