[R] Help with dates

Marc Girondot marc_grt at yahoo.fr
Fri Dec 29 06:29:00 CET 2017


Le 28/12/2017 à 18:13, Ramesh YAPALPARVI a écrit :
> Hi all,
>
> I’m struggling to get the dates in proper format.
> I have dates as factors and is in the form 02/27/34( 34 means 1934). If I use

Try this

x <- "02/27/34"
x2 <- paste0(substr(x, 1, 6), "19", substr(x, 7, 8))
as.Date(x2, format="%m/%d/%Y")
[1] "1934-02-27"

or

x2 <- gsub("(../../)(..)", "\\119\\2", x)

Marc

> as.Date with format %d%m%y it gets converted to 2034-02-27. I tried changing the origin in the as.Date command but nothing worked. Any help is appreciated.
>
> Thanks,
> Ramesh
> ______________________________________________
> 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.


-- 
__________________________________________________________
Marc Girondot, Pr

Laboratoire Ecologie, Systématique et Evolution
Equipe de Conservation des Populations et des Communautés
CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079
Bâtiment 362
91405 Orsay Cedex, France

Tel:  33 1 (0)1.69.15.72.30   Fax: 33 1 (0)1.69.15.73.53
e-mail: marc.girondot at u-psud.fr
Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html
Skype: girondot



More information about the R-help mailing list