Description Usage Arguments Details Value Author(s) See Also Examples

Convert time scales. The time scale "days" corresponds to 1 unit per day. The time scale "years" uses 1 unit for 1 year. It is used in any analysis that requires seasonal decomposition and/or elimination.

1 2 | ```
daystoyears(x, datemin=NULL, dateformat="m/d/Y")
yearstodays(x, xmin=NULL)
``` |

`x` |
A vector of time values |

`datemin` |
A character string representing the first date, using a format corresponding to |

`dateformat` |
The format used for the date in |

`xmin` |
The minimum value for the "days" time-scale |

The "years" time-scale uses one unit for each year. We deliberately "linearized" time in this time-scale and each year is considered to have exactly 365.25 days. There is thus no adjustment for lep years.
Indeed, a small shift (less than one day) is introduced. This could result, for some dates, especially the 31st December, or 1st January of a year to be considered as belonging to the next, or previous year, respectively!
Similarly, one month is considered to be 1/12 year, no mather if it has 28, 29, 30 or 31 days. Thus, the same warning applies: there are shifts in months introduced by this linearization of time!
This representation simplifies further calculations, especially regarding seasonal effects (a quarter is exactly 0.25 units for instance), but shifts introduced in time may or may not be a problem for your particular application
(if exact dates matters, do not use this; if shifts of up to one day is not significant, there is no problem, like when working on long-term biological series with years as units).
Notice that converting it back to "days", using `yearstodays()`

restablishes exact dates without errors. So, no data is lost, it just a conversion to a simplified (linearized) calendar!

A numerical vector of the same length as `x`

with the converted time-scale

Philippe Grosjean ([email protected]), Frédéric Ibanez ([email protected])

1 2 3 4 5 6 7 8 9 10 11 12 | ```
# A vector with a "days" time-scale (25 values every 30 days)
A <- (1:25)*30
# Convert it to a "years" time-scale, using 23/05/2001 (d/m/Y) as first value
B <- daystoyears(A, datemin="23/05/2001", dateformat="d/m/Y")
B
# Convert it back to "days" time-scale
yearstodays(B, xmin=30)
# Here is an example showing the shift introduced, and its consequence:
C <- daystoyears(unclass(as.Date(c("1970-1-1","1971-1-1","1972-1-1","1973-1-1"),
format = "%Y-%m-%d")))
C
``` |

```
Loading required package: boot
[1] 2001.389 2001.472 2001.554 2001.636 2001.718 2001.800 2001.882 2001.964
[9] 2002.047 2002.129 2002.211 2002.293 2002.375 2002.457 2002.539 2002.621
[17] 2002.704 2002.786 2002.868 2002.950 2003.032 2003.114 2003.196 2003.279
[25] 2003.361
[1] 30 60 90 120 150 180 210 240 270 300 330 360 390 420 450 480 510 540 570
[20] 600 630 660 690 720 750
[1] 1970.000 1970.999 1971.999 1973.001
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.