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

______________________________________________
R-help@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.

Reply via email to