1

I would like to include seasonality analysis in my model using a*sin(x)+b*cos(x), as where x is the day of the year.

For example "1990-1-1" retures 1; or like "1990-1-10" retures 10.

Also, since my data is in hourly base, what I was planning to do is to find out of the day of the year then times it by 24 then plus the striped out "hour number" to represents its order within a year. Could you also let me know if there are any better ways to do that.

Yu Deng
  • 1,051
  • 4
  • 18
  • 35
  • 1
    when trying to find the "day of the year" that's sometimes referred to as the "julian date." There are plenty of other questions on this site concerning julian dates. – MrFlick Nov 26 '14 at 04:35
  • Try this `as.POSIXlt(as.Date("1990-01-10"))$yday + 1` as `yday` is zero-indexed. – Dirk Eddelbuettel Nov 26 '14 at 04:36
  • Thanks, I never heard of "Julian date" before but now I know. Thanks for you help. – Yu Deng Nov 26 '14 at 04:47

1 Answers1

3

Format your dates and you're done:

x <- as.Date(c("1990-1-1","1990-1-10","2010-06-16"))
as.numeric(format(x,"%j"))
#[1]  1 10 167
thelatemail
  • 91,185
  • 12
  • 128
  • 188