One way (perhaps not the most efficient) > as.Date("2005-09-01","%Y-%m-%d") [1] "2005-09-01" > format(as.Date("2005-09-01","%Y-%m-%d"),"%Y") [1] "2005" > format(as.Date("2005-09-01","%Y-%m-%d"),"%d") [1] "01" > format(as.Date("2005-09-01","%Y-%m-%d"),"%m") [1] "09" >
See ?DateTimeClasses. Med venlig hilsen Frede Aakmann Tøgersen > -----Oprindelig meddelelse----- > Fra: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] På vegne af Arun Kumar Saha > Sendt: 18. september 2007 11:01 > Til: [EMAIL PROTECTED] > Emne: [R] Need help on "date" > > 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.