Hello, when I convert a factor like this a=01.10.2009 into a date using b=strptime(a, format="%d. %m. %Y"). It works very well. But when I try to convert c = 2009/10 into a date using d=strptime(c, format="%Y/%m") it doesnt work at all. I get d=NA. What did I do wrong? Thank you very much for your help! best regards Claudia
You have to supply a 'day' or the date is not known:> c = '2009/10' > d=strptime(paste0(c, '/1'), format="%Y/%m/%d") > d[1] "2009-10-01" On Mon, Jul 23, 2012 at 9:05 AM, paladini <paladini at beuth-hochschule.de> wrote:> Hello, > when I convert a factor like this a=01.10.2009 > into a date using b=strptime(a, format="%d. %m. %Y"). > It works very well. > But when I try to convert c = 2009/10 into a date using > d=strptime(c, format="%Y/%m") > it doesnt work at all. I get d=NA. > What did I do wrong? > Thank you very much for your help! > > best regards > > > Claudia > > ______________________________________________ > 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.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
HI, You can try, library(zoo) c2<-"2009/10" ?as.Date(as.yearmon(c2,"%Y/%m")) [1] "2009-10-01" str(c3) ?Date[1:1], format: "2009-10-01" A.K. ----- Original Message ----- From: paladini <paladini at beuth-hochschule.de> To: r-help at r-project.org Cc: Sent: Monday, July 23, 2012 9:05 AM Subject: [R] date conversation Hello, when I convert a factor like this? a=01.10.2009 into a date using b=strptime(a, format="%d. %m. %Y"). It works very well. But when I try to convert c = 2009/10 into a date using d=strptime(c, format="%Y/%m") it doesnt work at all. I get d=NA. What did I do wrong? Thank you very much for your help! best regards Claudia ______________________________________________ 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.