Message-ID: <1BDAE2969943D540934EE8B4EF68F95FB22F48CDF7@EXNSW-MBX03.nexus.csiro.au>
Date: 2009-03-31T07:28:46Z
From: Bill Venables
Subject: Convert Character to Date
In-Reply-To: <662076.42273.qm@web112213.mail.gq1.yahoo.com>
If you want the vector to be a Date you need to specify a date at least down to the day. Otherwise the date is not well defined and becomes <NA> as you noted.
Perhaps the easiest thing is to give it a particular day of the month, e.g. the first, or the 15 (the "ides"), or ...
> x <- as.Date(paste("1990-January", 1, sep="-"), format = "%Y-%B-%d")
> x
[1] 1990-01-01
Now if you want to display the date suppressing the dummy day, you can
> y <- format(x, "%Y-%B")
> y
[1] "1990-January"
Bill Venables
http://www.cmis.csiro.au/bill.venables/
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Bob Roberts
Sent: Tuesday, 31 March 2009 5:14 PM
To: r-help at r-project.org
Subject: [R] Convert Character to Date
Hello,
I have a date in the format Year-Month Name (e.g. 1990-January) and R classes it as a character. I want to convert this character into a date format, but when I try as.Date(1990-January, "%Y-%B"), I get back NA. The function strptime also gives me NA back. Thanks.
[[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.