[R] Need help on "date"

Frede Aakmann Tøgersen FredeA.Togersen at agrsci.dk
Tue Sep 18 12:43:30 CEST 2007


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: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] På vegne af Arun Kumar Saha
> Sendt: 18. september 2007 11:01
> Til: r-help at stat.math.ethz.ch
> 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 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