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 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
Your dates have an incomplete year information with 34. R assumes that 00-68 are 2000 to 2068 and 69 to 99 are 1969 to 1999. See ?strptime and the details for %y. You can either append ?19? to the start of your year variable to make it completely express the year or check if the date is in the future (assuming all dates should be in the past) and subtract 100 years from the date.> On Dec 28, 2017, at 11:13 AM, Ramesh YAPALPARVI <ramesh.yapalparvi at icloud.com> wrote: > > 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 > > 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.
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 useTry 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
Mostly agree, except that I would suggest hardcoding the notion of "in the future", so that you don't get surprises when someone reruns your code 20 years from now. -pd> On 28 Dec 2017, at 21:54 , Simmering, Jacob E <jacob-simmering at uiowa.edu> wrote: > > Your dates have an incomplete year information with 34. R assumes that 00-68 are 2000 to 2068 and 69 to 99 are 1969 to 1999. See ?strptime and the details for %y. > > You can either append ?19? to the start of your year variable to make it completely express the year or check if the date is in the future (assuming all dates should be in the past) and subtract 100 years from the date. > > >> On Dec 28, 2017, at 11:13 AM, Ramesh YAPALPARVI <ramesh.yapalparvi at icloud.com> wrote: >> >> 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 >> >> 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. > > ______________________________________________ > 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com