[R] Date functions

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jan 30 16:43:20 CET 2009


# 1
d <- Sys.Date()
seq(d, len = 2, by = "2 months")[2]

# 2
as.numeric(format(d, "%w")) # 0 = Sunday
# or
format(d, "%a")

See R News 4/1 for more info and the table at the end of it in particular.

On Fri, Jan 30, 2009 at 9:54 AM, ehxpieterse
<eduard.pieterse at macquarie.com> wrote:
>
> Hi there,
>
> I am completely new to R and would like to do two things with date
> functions:
> 1. Compute any date from a specified starting point, e.g. x - 2 months
> 2. How do I determine the weekday of any given date?
>
> Thanks in advance
> --
> View this message in context: http://www.nabble.com/Date-functions-tp21748580p21748580.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list