[R] finding the year of a date

2010-10-25 Thread Dimitri Liakhovitski
I know that I can use as.yearmon in the package zoo to find the year
and the month of a date.
I can use as. yearqtr to find the year and the quarter.
But how can one find just the year of a date?

Thanks a lot!

-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com

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


Re: [R] finding the year of a date

2010-10-25 Thread Henrique Dallazuanna
Try this:

format(Sys.Date(), %Y)

On Mon, Oct 25, 2010 at 2:38 PM, Dimitri Liakhovitski 
dimitri.liakhovit...@gmail.com wrote:

 I know that I can use as.yearmon in the package zoo to find the year
 and the month of a date.
 I can use as. yearqtr to find the year and the quarter.
 But how can one find just the year of a date?

 Thanks a lot!

 --
 Dimitri Liakhovitski
 Ninah Consulting
 www.ninah.com

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




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

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


Re: [R] finding the year of a date

2010-10-25 Thread Gabor Grothendieck
On Mon, Oct 25, 2010 at 12:38 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 I know that I can use as.yearmon in the package zoo to find the year
 and the month of a date.
 I can use as. yearqtr to find the year and the quarter.
 But how can one find just the year of a date?

 Thanks a lot!

Here are three ways.  The first uses the fact that the year is the
whole number part of a yearmon object.

 library(zoo)
 d - Sys.Date()
 floor(as.numeric(as.yearmon(d)))
[1] 2010

 as.numeric(format(d, %Y))
[1] 2010

 as.POSIXlt(d)$year + 1900
[1] 2010

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] finding the year of a date

2010-10-25 Thread Dimitri Liakhovitski
Thank you very much!
Dimitri

On Mon, Oct 25, 2010 at 12:46 PM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 On Mon, Oct 25, 2010 at 12:38 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 I know that I can use as.yearmon in the package zoo to find the year
 and the month of a date.
 I can use as. yearqtr to find the year and the quarter.
 But how can one find just the year of a date?

 Thanks a lot!

 Here are three ways.  The first uses the fact that the year is the
 whole number part of a yearmon object.

 library(zoo)
 d - Sys.Date()
 floor(as.numeric(as.yearmon(d)))
 [1] 2010

 as.numeric(format(d, %Y))
 [1] 2010

 as.POSIXlt(d)$year + 1900
 [1] 2010

 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com




-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com

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