Help with strftime error "character string is not in a standard unambiguous format"

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with strftime error "character string is not in a standard unambiguous format"

Chris Evans
I am trying to read activity data created by Garmin. It outputs dates like this:

"Thu, 25 Aug 2016 6:34 PM"

The problem that has stumped me is this:

> strftime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")
Error in as.POSIXlt.character(x, tz = tz) :
  character string is not in a standard unambiguous format

I _thought_ I had this running OK but that error is catching me now.  I think I've read ?strftime and written that format string correctly to match the input but I'm stumped now.

Can someone advise me?  Many thanks in advance,

Chris


> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 10586)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252  
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

loaded via a namespace (and not attached):
[1] compiler_3.3.1 tools_3.3.1  
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with strftime error "character string is not in a standard unambiguous format"

Peter Dalgaard-2

> On 12 Sep 2016, at 07:57 , Chris Evans <[hidden email]> wrote:
>
>> strftime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")

strptime, not strftime...

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with strftime error "character string is not in a standard unambiguous format"

jeremiah rounds-2
In reply to this post by Chris Evans
Not sure what the issue is with the provided code  but note:
library(lubridate)
 lubridate::dmy_hm("Thu, 25 Aug 2016 6:34 PM")
[1] "2016-08-25 18:34:00 UTC"


Though if you go that route: set the TZ because on the timestamp it is
ambiguous.

On Sun, Sep 11, 2016 at 10:57 PM, Chris Evans <[hidden email]> wrote:

> I am trying to read activity data created by Garmin. It outputs dates like
> this:
>
> "Thu, 25 Aug 2016 6:34 PM"
>
> The problem that has stumped me is this:
>
> > strftime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")
> Error in as.POSIXlt.character(x, tz = tz) :
>   character string is not in a standard unambiguous format
>
> I _thought_ I had this running OK but that error is catching me now.  I
> think I've read ?strftime and written that format string correctly to match
> the input but I'm stumped now.
>
> Can someone advise me?  Many thanks in advance,
>
> Chris
>
>
> > sessionInfo()
> R version 3.3.1 (2016-06-21)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 10 x64 (build 10586)
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252
> [2] LC_CTYPE=English_United Kingdom.1252
> [3] LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United Kingdom.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> loaded via a namespace (and not attached):
> [1] compiler_3.3.1 tools_3.3.1
> >
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with strftime error "character string is not in a standard unambiguous format"

Jeff Newmiller
In reply to this post by Chris Evans
Perhaps use the correct function.  (Just one little letter off...)
--
Sent from my phone. Please excuse my brevity.

On September 11, 2016 10:57:39 PM PDT, Chris Evans <[hidden email]> wrote:

>I am trying to read activity data created by Garmin. It outputs dates
>like this:
>
>"Thu, 25 Aug 2016 6:34 PM"
>
>The problem that has stumped me is this:
>
>> strftime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")
>Error in as.POSIXlt.character(x, tz = tz) :
>  character string is not in a standard unambiguous format
>
>I _thought_ I had this running OK but that error is catching me now.  I
>think I've read ?strftime and written that format string correctly to
>match the input but I'm stumped now.
>
>Can someone advise me?  Many thanks in advance,
>
>Chris
>
>
>> sessionInfo()
>R version 3.3.1 (2016-06-21)
>Platform: x86_64-w64-mingw32/x64 (64-bit)
>Running under: Windows 10 x64 (build 10586)
>
>locale:
>[1] LC_COLLATE=English_United Kingdom.1252
>[2] LC_CTYPE=English_United Kingdom.1252  
>[3] LC_MONETARY=English_United Kingdom.1252
>[4] LC_NUMERIC=C                          
>[5] LC_TIME=English_United Kingdom.1252    
>
>attached base packages:
>[1] stats     graphics  grDevices utils     datasets  methods   base  
>
>
>loaded via a namespace (and not attached):
>[1] compiler_3.3.1 tools_3.3.1  
>>
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with strftime error "character string is not in a standard unambiguous format"

Daniel Nordlund-3
In reply to this post by Chris Evans
On 9/11/2016 10:57 PM, Chris Evans wrote:

> I am trying to read activity data created by Garmin. It outputs dates like this:
>
> "Thu, 25 Aug 2016 6:34 PM"
>
> The problem that has stumped me is this:
>
>> strftime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")
> Error in as.POSIXlt.character(x, tz = tz) :
>   character string is not in a standard unambiguous format
>
> I _thought_ I had this running OK but that error is catching me now.  I think I've read ?strftime and written that format string correctly to match the input but I'm stumped now.
>
> Can someone advise me?  Many thanks in advance,
>
> Chris
>
>
>> sessionInfo()
> R version 3.3.1 (2016-06-21)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 10 x64 (build 10586)
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252
> [2] LC_CTYPE=English_United Kingdom.1252
> [3] LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United Kingdom.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> loaded via a namespace (and not attached):
> [1] compiler_3.3.1 tools_3.3.1
>>
>
> ______________________________________________
> [hidden email] 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.
>

I have always used strptime() for this task, and

 > strptime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")
[1] "2016-08-25 18:34:00 PDT"

works for me.


Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with strftime error "character string is not in a standard unambiguous format"

Enrico Schumann-2
In reply to this post by Chris Evans
On Mon, 12 Sep 2016, Chris Evans <[hidden email]> writes:

> I am trying to read activity data created by Garmin. It outputs dates like this:
>
> "Thu, 25 Aug 2016 6:34 PM"
>
> The problem that has stumped me is this:
>
>> strftime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")
> Error in as.POSIXlt.character(x, tz = tz) :
>   character string is not in a standard unambiguous format


Didn't you mean strptime?
                   ^
  > strptime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")

  ## [1] "2016-08-25 18:34:00 CEST"


> I _thought_ I had this running OK but that error is catching me now.
> I think I've read ?strftime and written that format string correctly
> to match the input but I'm stumped now.
>
> Can someone advise me?  Many thanks in advance,
>
> Chris
>
>
>> sessionInfo()
> R version 3.3.1 (2016-06-21)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 10 x64 (build 10586)
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252
> [2] LC_CTYPE=English_United Kingdom.1252  
> [3] LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C                          
> [5] LC_TIME=English_United Kingdom.1252    
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base    
>
> loaded via a namespace (and not attached):
> [1] compiler_3.3.1 tools_3.3.1  
>>
>
> ______________________________________________
> [hidden email] 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.

--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with strftime error "character string is not in a standard unambiguous format"

Ismail SEZEN
In reply to this post by Chris Evans
It should be strptime for character vectors.

strptime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p”)

> On 12 Sep 2016, at 08:57, Chris Evans <[hidden email]> wrote:
>
>> strftime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with strftime error "character string is not in a standard unambiguous format"

Chris Evans
OK. I'm an idiot (not for the first time and, sadly, no doubt not for the last). strptime() was all that was needed: just that one pesky character and I can't remember now why I went astray there, but thanks to all who supplied the answer and all who supplied additional useful information.

As ever, deeply indebted to the R and R-help communities,

Chris

> From: "Ismail SEZEN" <[hidden email]>
> To: "Chris Evans" <[hidden email]>
> Cc: "r-help" <[hidden email]>
> Sent: Monday, 12 September, 2016 10:36:51
> Subject: Re: [R] Help with strftime error "character string is not in a standard
> unambiguous format"

> It should be strptime for character vectors.

> strptime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p”)

>> On 12 Sep 2016, at 08:57, Chris Evans < [hidden email] > wrote:

>>> strftime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with strftime error "character string is not in a standard unambiguous format"

Peter Dalgaard-2

On 12 Sep 2016, at 12:33 , Chris Evans <[hidden email]> wrote:

> OK. I'm an idiot (not for the first time and, sadly, no doubt not for the last). strptime() was all that was needed: just that one pesky character and I can't remember now why I went astray there, but thanks to all who supplied the answer and all who supplied additional useful information.

Usually happens because you think it is p for print, so the other one must be f. (It's really _p_arse and _f_ormat.)

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] 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.