On 08/16/2010 08:22 PM, Jim Lemon wrote:
On 08/16/2010 03:27 PM, Dong-Hee Koh wrote:
Hello,

I am trying to read a database exported from SAS.

It is form of csv, and the date format reads '02-Feb-99'.
I used following code to convert character to date format,
db$dob<-as.Date(db$dob, format="%d-%b-%y").
but it doesn't work, only seems NA.

What's wrong with this code?

Hi Dong-Hee,
The problem is not with your command, but most likely the reading in of
the data. If you just use read.csv, your dates will probably be read in
as factors. You can correct this at the reading stage:

db<-read.csv(<filename>,as.is=TRUE)

or at the conversion stage:

db$dob<-as.Date(as.character(db$dob,"%d-%b-%y"))

Oops, sorry, misplaced parenthesis

db$dob<-as.Date(as.character(db$dob),"%d-%b-%y")

Jim

______________________________________________
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.

Reply via email to