Skip to content
Prev 337098 / 398528 Next

write function to convert to date or delete

That error occurs when as.POSIXlt is looking for a format
with which to parse the strings.  If you supply a format for the
date then as.POSIXlt will not give this error - it will just return
NA's for the entries that do not match the format.
   > as.POSIXlt(c("2013-02-28", "Feb 28, 2013"))
   Error in as.POSIXlt.character(c("2013-02-28", "Feb 28, 2013")) :
     character string is not in a standard unambiguous format
   > as.POSIXlt(c("2013-02-28", "Feb 28, 2013"), format="%Y-%m-%d")
   [1] "2013-02-28" NA
   > as.POSIXlt(c("2013-02-28", "Feb 28, 2013"), format="%B %d, %Y")
   [1] NA           "2013-02-28"

If the strings may be in one of several formats, loop through
the formats and decide which to accept. 

Bill Dunlap
TIBCO Software
wdunlap tibco.com