Re: [R] R Date Time

2017-04-25 Thread Dirk Eddelbuettel

On 25 April 2017 at 18:05, Duncan Murdoch wrote:
| On 25/04/2017 5:41 PM, Dirk Eddelbuettel wrote:
| >
| > On 25 April 2017 at 16:04, Jeff Reichman wrote:
| > | R Users
| > |
| > | Having problems converting the following DTG into an R recognized 
date/time
| > | field
| > |
| > | 01-01-2016T14:02:23.325
| > |
| > | Would I separate it into a date field and time filed then put it back
| > | together???
| >
| > The anytime package (on CRAN) does this (and other date or datetime input
| > variants) without requiring a format:
| >
| >   R> library(anytime)
| >   R> anytime("01-01-2016T14:02:23.325")
| >   [1] "2016-01-01 14:02:23.325 CST"
| 
| How does it decide between MDY and DMY orderings in dates?  Doesn't 
| matter for this example, but it would for "01-02-2016T14:02:23.325"

See 

http://dirk.eddelbuettel.com/code/anytime.html

https://github.com/eddelbuettel/anytime

https://github.com/eddelbuettel/anytime/blob/master/src/anytime.cpp#L43-L106

for overview(s), some comments, notes and in particular the set of formats.

It has a strong preference for sane (ie ISO formats) but in the case of
ambiguity it (grudingly) prefers the (silly) US way:

R> anytime("01-02-2003")
[1] "2003-01-02 CST"
R>

But I try not to miss an opportunity that the format should really not be used.

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
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.


Re: [R] R Date Time

2017-04-25 Thread Duncan Murdoch

On 25/04/2017 5:41 PM, Dirk Eddelbuettel wrote:


On 25 April 2017 at 16:04, Jeff Reichman wrote:
| R Users
|
| Having problems converting the following DTG into an R recognized date/time
| field
|
| 01-01-2016T14:02:23.325
|
| Would I separate it into a date field and time filed then put it back
| together???

The anytime package (on CRAN) does this (and other date or datetime input
variants) without requiring a format:

  R> library(anytime)
  R> anytime("01-01-2016T14:02:23.325")
  [1] "2016-01-01 14:02:23.325 CST"


How does it decide between MDY and DMY orderings in dates?  Doesn't 
matter for this example, but it would for "01-02-2016T14:02:23.325"


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.


Re: [R] R Date Time

2017-04-25 Thread Dirk Eddelbuettel

On 25 April 2017 at 16:04, Jeff Reichman wrote:
| R Users
| 
| Having problems converting the following DTG into an R recognized date/time
| field
| 
| 01-01-2016T14:02:23.325
| 
| Would I separate it into a date field and time filed then put it back
| together???

The anytime package (on CRAN) does this (and other date or datetime input
variants) without requiring a format:

  R> library(anytime)
  R> anytime("01-01-2016T14:02:23.325")
  [1] "2016-01-01 14:02:23.325 CST"
  R>

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
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.


Re: [R] R Date Time

2017-04-25 Thread William Dunlap via R-help
> z <- as.POSIXct("01-01-2016T14:02:23.325", format="%d-%m-%YT%H:%M:%OS")
> dput(z)
structure(1451685743.325, class = c("POSIXct", "POSIXt"), tzone = "")
> z
[1] "2016-01-01 14:02:23 PST"
> format(z, "%H:%M:%OS3 on %b %d, %Y")
[1] "14:02:23.325 on Jan 01, 2016"

(Don't separate the date and time parts because some times don't exist on
some days.)


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Tue, Apr 25, 2017 at 2:04 PM, Jeff Reichman 
wrote:

> R Users
>
>
>
> Having problems converting the following DTG into an R recognized date/time
> field
>
>
>
> 01-01-2016T14:02:23.325
>
>
>
> Would I separate it into a date field and time filed then put it back
> together???
>
>
>
> Jeff
>
>
> [[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.
>

[[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.


Re: [R] R Date Time

2017-04-25 Thread Duncan Murdoch

On 25/04/2017 5:04 PM, Jeff Reichman wrote:

R Users



Having problems converting the following DTG into an R recognized date/time
field



01-01-2016T14:02:23.325



Would I separate it into a date field and time filed then put it back
together???



This appears to work (though I'm not sure whether you are using MDY or 
DMY; I used DMY):


strptime("01-01-2016T14:02:23.325", format="%d-%m-%YT%H:%M:%OS")

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.


[R] R Date Time

2017-04-25 Thread Jeff Reichman
R Users

 

Having problems converting the following DTG into an R recognized date/time
field

 

01-01-2016T14:02:23.325

 

Would I separate it into a date field and time filed then put it back
together???

 

Jeff


[[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.