Re: [R] Changing string to date
On 8/30/2013 3:36 AM, Uwe Ligges wrote: > > > On 30.08.2013 11:59, Christofer Bogaso wrote: >> Hello again, >> >> I have a string which I need to put in some legitimate date format. >> >> My string is: "MAY-14" >> >> And output format would be "05/01/2014", this should be of Date class, >> so that I can make some sensible calculation with it. >> >> I have tried this without any success: >> >>> as.Date("MAY-14", format = "%b-%y") >> [1] NA >> > > > You must have set an English locale (to recognize the word May as a > month) and you have to add a day. You can use the yearmon class from the zoo package as an intermediary to get around having to explicitly add a day library("zoo") as.Date(as.yearmon("MAY-14", format="%b-%y")) gives > as.Date(as.yearmon("MAY-14", format="%b-%y")) [1] "2014-05-01" > Best, > Uwe Ligges > > > >> >> Can somebody help me how I can achieve that? >> >> Thanks and regards, >> >> __ >> R-help@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. >> > -- Brian S. Diggs, PhD Senior Research Associate, Department of Surgery Oregon Health & Science University __ R-help@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.
Re: [R] Changing string to date
Hi as.Date(paste("MAY-14","-01", sep=""), format = "%b-%y-%d") Shall be OK. Change output format by ?format. Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Christofer Bogaso > Sent: Friday, August 30, 2013 12:00 PM > To: r-help > Subject: [R] Changing string to date > > Hello again, > > I have a string which I need to put in some legitimate date format. > > My string is: "MAY-14" > > And output format would be "05/01/2014", this should be of Date class, > so that I can make some sensible calculation with it. > > I have tried this without any success: > > > as.Date("MAY-14", format = "%b-%y") > [1] NA > > > Can somebody help me how I can achieve that? > > Thanks and regards, > > __ > R-help@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. __ R-help@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.
Re: [R] Changing string to date
On 30.08.2013 11:59, Christofer Bogaso wrote: Hello again, I have a string which I need to put in some legitimate date format. My string is: "MAY-14" And output format would be "05/01/2014", this should be of Date class, so that I can make some sensible calculation with it. I have tried this without any success: as.Date("MAY-14", format = "%b-%y") [1] NA You must have set an English locale (to recognize the word May as a month) and you have to add a day. Best, Uwe Ligges Can somebody help me how I can achieve that? Thanks and regards, __ R-help@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. __ R-help@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.
[R] Changing string to date
Hello again, I have a string which I need to put in some legitimate date format. My string is: "MAY-14" And output format would be "05/01/2014", this should be of Date class, so that I can make some sensible calculation with it. I have tried this without any success: > as.Date("MAY-14", format = "%b-%y") [1] NA Can somebody help me how I can achieve that? Thanks and regards, __ R-help@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.