There have been a few solutions already but I thought I would add one that uses chron:
> library(chron) > attach(month.day.year(chron(unclass(as.Date("2005-09-01"))))) > year [1] 2005 > month [1] 9 > day [1] 1 or perhaps cleaner: library(chron) with(month.day.year(chron(unclass(as.Date("2006-09-01")))), { ... computations involving variables month, day and year ... } See R News 4/1 help desk article for info on dates. Particularly the table at the end. On 9/18/07, Arun Kumar Saha <[EMAIL PROTECTED]> 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.