Seems to work fine in my testing: > x <- read.csv(textConnection("date,value + 2009-01-01,10 + 2009-02-01,1 + 'NA', 3"), colClasses=c("Date", 'integer')) > > str(x) 'data.frame': 3 obs. of 2 variables: $ date :Class 'Date' num [1:3] 14245 14276 NA $ value: int 10 1 3 > x <- read.csv(textConnection("date,value + 2009-01-01,10 + 2009-02-01,1 + NA, 3"), colClasses=c("Date", 'integer')) > > str(x) 'data.frame': 3 obs. of 2 variables: $ date :Class 'Date' num [1:3] 14245 14276 NA $ value: int 10 1 3 >
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. On Wed, Nov 25, 2009 at 12:38 PM, <nabble.30.miller_2...@spamgourmet.com> wrote: > Hello - > > I have a csv file with a few date columns. Some of the records have an > "NA" character string instead of the date. When I attempt to use > read.csv() and typecast the columns using colClasses, I receive the > following error: > Error in charToDate(x) : > character string is not in a standard unambiguous format > > Similarly, the following command produces the same error: > as.Date("NA") > > However, as.Date(NA) performs as documented. > > Can we enhance the as.Date() function to convert "NA" strings into NA > value prior to type conversion? > > Thanks! > > ______________________________________________ > 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ 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.