[R] Need help on "date"
Jeffrey Robert Spies
jspies at nd.edu
Tue Sep 18 16:31:57 CEST 2007
And one using regular expressions:
x <- "2005-09-01"
pattern <- '([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})'
y <- sub(pattern, '\\1', x)
m <- sub(pattern, '\\2', x)
d <- sub(pattern, '\\3', x)
-- Jeff.
On Sep 18, 2007, at 5:00 AM, Arun Kumar Saha wrote:
> Dear all,
>
> I have a variable 'x' like that:
>
>> x
> [1] "2005-09-01"
>
> Here, 2005 represents year, 09 month and 01 day.
>
> Now I want to create three variables naming: y, m, and d such that:
>
> y = 2005
> m = 09
> d = 01
>
> can anyone tell me how to do that?
>
> Regards,
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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