Thank you all very much, very helpful! :) I'm just curious, what does strptime(), strftime(), as.POSIXlt.(), and as.POSIXct() stand for?
On Sat, Feb 2, 2019 at 10:41 AM Jeff Newmiller <jdnew...@dcn.davis.ca.us> wrote: > ... and in general, you need to specify the time zone to avoid surprises. > In many cases this can be as simple as > > Sys.setenv(TZ="GMT") > > but it can be specific to your data set also. > > On February 2, 2019 7:09:46 AM PST, Duncan Murdoch < > murdoch.dun...@gmail.com> wrote: > >On 01/02/2019 10:45 p.m., C W wrote: > >> Dear R community, > >> > >> I am working with dates. And I get the following error: > >>> strftime(dat[20], format="%H:%M") > >> Error in as.POSIXlt.character(as.character(x), ...) : > >> character string is not in a standard unambiguous format > > > >You are using the wrong function: strftime() formats a time object as > >a > >character string. You want strptime() to convert character (or factor > >in your case) to a time object. > > > >But you need to give the format for the full string, not just the time > >at the end. > > > >If you really were intending to extract times from dat, then you need > >both conversions: > > > > > strftime(strptime(dat, format="%m/%d/%y %H:%M"), format = "%H:%M") > > [1] "11:32" "11:42" "12:17" "12:31" "12:50" "14:10" "14:19" "14:59" > >"15:57" "16:00" "16:46" "16:51" "17:35" "17:59" "18:17" "19:07" "19:08" > >[18] "19:31" "21:21" "06:00" "06:20" "06:37" "06:40" "06:46" "07:20" > >"07:47" "07:50" "07:54" "08:11" "08:23" "08:31" "08:33" "08:43" "09:04" > >[35] "09:09" "09:30" "09:59" "10:01" "10:03" "10:05" > > > >Duncan Murdoch > > > >______________________________________________ > >R-help@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/posting-guide.html > >and provide commented, minimal, self-contained, reproducible code. > > -- > Sent from my phone. Please excuse my brevity. > [[alternative HTML version deleted]] ______________________________________________ R-help@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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.