[R] Help with creating a ts (time series) object with daily sampling values

From: Pamela Allen <pallen_at_hatfieldgroup.com>
Date: Thu, 24 Mar 2011 12:24:22 -0700 (PDT)

Hi All,  

I have a data set of daily measurements of river flow. I would like to create a "ts" object from this data.  

Here's a sample data set:

date <- as.Date(c(1:300), format="%Y")

year=as.numeric(format(date, format = "%Y"))

month=as.numeric(format(date, format = "%m"))

julianday=as.numeric(format(date, format = "%j"))


flow <- sin(2*pi/53*c(1:300))

data <- cbind.data.frame(date,year,month,julianday,week, flow)  

I know how to do this with exact dates using the irts package:



data=cbind.data.frame(data,posixlt.time=as.POSIXlt(data$date, "PDT")) ##To create dates based on POSIXlt

data.irts=irts(data$posixlt.time, data$flow)  

But I would like the time series object to be in the "ts" format. I tried using this code:  

data.ts=ts(data$flow, start=c(data$year[1], data$julianday[1]), frequency=365)  

Which does work, but I worry about the influence of leap years, since my data set is quite large. What is the way to properly code a ts object with daily measurements? Thank you!  


Pam Allen

Vancouver, BC  

R-help_at_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. Received on Thu 24 Mar 2011 - 20:14:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Mar 2011 - 20:20:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive