The problem occurs because no commonly used format works on
all your date strings. If you give as.POSIXlt the format you want to
use then items that don't match the format will be treated as NA's.
Use is.na() to find them.
> d <- c("2017-12-25", "2018-01-01",
"10/31/2018")
> as.POSIXlt(d)
Error in as.POSIXlt.character(d) :
character string is not in a standard unambiguous
format> as.POSIXlt(d, format="%Y-%m-%d")
[1] "2017-12-25 PST" "2018-01-01 PST"
NA> as.POSIXlt(d, format="%m/%d/%Y")
[1] NA NA "2018-10-31 PDT"
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Fri, Jul 20, 2018 at 10:43 AM, Rich Shepard <rshepard at
appl-ecosys.com>
wrote:
> The structure of the dataframe is
>
> str(wy2016)
> 'data.frame': 8784 obs. of 4 variables:
> $ date : chr "2015-10-01" "2015-10-01"
"2015-10-01" "2015-10-01" ...
> $ time : chr "00:00" "01:00" "02:00"
"03:00" ...
> $ elev : num 90.7 90.7 90.7 90.7 90.7 ...
> $ myDate: Date, format: "2015-10-01" "2015-10-01" ...
>
> The command and results on this dataframe is:
> wy2016$myTime <- as.POSIXct(paste(wy2016$date, wy2016$time))
> Error in as.POSIXlt.character(x, tz, ...) :
> character string is not in a standard unambiguous format
>
> Data for other water years do not throw this error. How can I identify
> which row(s) among the 8784 have a date or time formatting error?
>
> Rich
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]