[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
?Date
at the R prompt. Continue with
?as.Date
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
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
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
>includes
>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
>a
>"1" otherwise. Note that my dataset includes dates from 1979-2012, so it
>is
>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.
>
>Best,
>Brian
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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