[R] Using dates in R

MacQueen, Don macqueen1 at llnl.gov
Wed Mar 4 19:39:59 CET 2015

Your hunch is wrong.

Start by typing
at the R prompt. Continue with

Then to find out if the date is earlier than today
  delta <- thedate - Sys.Date()
(of course, that will change if you use it tomorrow)
Getting your indicator variable can be done very easily with base R; no
packages needed.


Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550

On 3/4/15, 6:54 AM, "Brian Hamel" <bh1605a at student.american.edu> wrote:

>Hi all,
>I have a dataset that includes a "date" variable. Each observation
>a date in the form of 2/15/15, for example. I'm looking to create a new
>indicator variable that is based on the date variable. So, for example, if
>the date is earlier than today, I would need a "0" in the new column, and
>"1" otherwise. Note that my dataset includes dates from 1979-2012, so it
>not one-year (this means I can't easily create a new variable 1-365).
>How does R handle dates? My hunch is "not well," but perhaps there is a
>package that can help me with this. Let me know if you have any
>recommendations as to how this can be done relatively easily.
>Thanks! Appreciate it.
>	[[alternative HTML version deleted]]
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list