[R] date

Ista Zahn izahn at psych.rochester.edu
Thu Sep 2 16:48:45 CEST 2010


Hi Dunia,
You need to convert the character strings to Dates.

time1 <- as.Date(c("21/04/2005","23/05/2005","11/04/2005"), "%d/%m/%Y")
time2 <- as.Date(c("15/07/2009", "03/06/2008", "15/10/2005"), "%d/%m/%Y")

time2-time1


Best,
Ista

On Thu, Sep 2, 2010 at 10:32 AM, Dunia Scheid <dunia.scheid at gmail.com> wrote:
> Hello all,
>
> I've 2 strings that representing the start and end values of a date and
> time.
> For example,
> time1 <- c("21/04/2005","23/05/2005","11/04/2005")
> time2 <- c("15/07/2009", "03/06/2008", "15/10/2005")
> as.difftime(time1,time2)
> Time differences in secs
> [1] NA NA NA
> attr(,"tzone")
> [1] ""
>
> How can i calculate the difference  between this 2 string?
>
> Regards,
> Dunia
>
>        [[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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list