[R] date conversion
Joshua Wiley
jwiley.psych at gmail.com
Fri Sep 3 23:15:22 CEST 2010
Hi,
I think you just need to add the format = argument. Does this help?
> x <- factor("01-11-2007")
> as.character(x)
[1] "01-11-2007"
> as.Date(as.character(x), format = "%d-%m-%Y")
[1] "2007-11-01"
Cheers,
Josh
On Fri, Sep 3, 2010 at 2:11 PM, André de Boer <rnieuws at gmail.com> wrote:
>
> Hello,
>
> I have a dataframe with data such as:
> > dat$BEGINDATUM[3]
> [1] 13-09-2007
> > dat$BEGINDATUM[4]
> [1] 01-11-2007
>
> > class(dat$BEGINDATUM[3])
> [1] "factor"
>
> Now I need to make calculation with these dates.
> But I get these result:
> > as.date(as.character(dat$BEGINDATUM[3]))
> [1] <NA>
> > as.date(as.character(dat$BEGINDATUM[4]))
> [1] 11Jan2007
>
> How can i convert these factors to make calculations possible.
>
> Thanks for the answer,
> Andre
>
> [[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.
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
More information about the R-help
mailing list