[R] Extract pattern from string

Justin Haynes jtor14 at gmail.com
Tue Nov 15 18:57:27 CET 2011


take a look at the structure of what Sys.time returns.

str(Sys.time)

and now at ?strptime!

> format(Sys.time(),format='%d-%H-%M-%S')
[1] "15-09-55-55"

> format(Sys.time(),format='%Y')
[1] "2011"
> format(Sys.time(),format='%m')
[1] "11"
>


Hope that helps,

Justin

On Tue, Nov 15, 2011 at 9:48 AM, syrvn <mentor_ at gmx.net> wrote:
> Hello,
>
> with Sys.time() you get the following string:
>
> "2011-11-15 16:25:55 GMT"
>
> How can I extract the following substrings:
>
> year <- 2011
>
> month <- 11
>
> day_time <- 15_16_25_55
>
>
> Cheers,
>
> Syrvn
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Extract-pattern-from-string-tp4073432p4073432.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>



More information about the R-help mailing list