[R] calculations with dates

jim holtman jholtman at gmail.com
Sun Aug 29 14:27:31 CEST 2010


Try this:

> x
  startdate   enddate
1 27SEP2005 01JAN2006
> x$start <- as.Date(x$startdate, format="%d%b%Y")
> x$end <- as.Date(x$enddate, format="%d%b%Y")
> x
  startdate   enddate      start        end
1 27SEP2005 01JAN2006 2005-09-27 2006-01-01
> x$duration <- x$end - x$start
> x
  startdate   enddate      start        end duration
1 27SEP2005 01JAN2006 2005-09-27 2006-01-01  96 days
>


On Sun, Aug 29, 2010 at 8:20 AM, André de Boer <rnieuws at gmail.com> wrote:
> Hi,
>
> I have a data.frame with factors in columns like
>
> startdate      enddate
> 27SEP2005 01JAN2006
>
> How can I calculate the duration between those two dates and move this in a
> extra column in the data.frame.
>
> Thanks,
> André
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list