Hi,
Anyone knows what would be a short way of extracting a month from a date in
numeric or integer format?
months("1979-12-20")
returns
"December" in character format.
How could I get 12 in numeric or integer format?
Thanks!
G.
[[alternative HTML version deleted]]
Hi,
perhaps:
format.Date(as.Date("1979-12-20"), "%m")
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
On 21/08/07, Gonçalo Ferraz <gferraz29@gmail.com>
wrote:>
> Hi,
> Anyone knows what would be a short way of extracting a month from a date
> in
> numeric or integer format?
>
> months("1979-12-20")
> returns
> "December" in character format.
>
> How could I get 12 in numeric or integer format?
>
> Thanks!
>
> G.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>
[[alternative HTML version deleted]]
On 8/21/07, Gon?alo Ferraz <gferraz29 at gmail.com> wrote:> Hi, > Anyone knows what would be a short way of extracting a month from a date in > numeric or integer format? > > months("1979-12-20") > returns > "December" in character format. > > How could I get 12 in numeric or integer format? >Here are a few solutions: format(as.Date("1979-12-20"), "%m") as.POSIXlt(as.Date("1979-12-20"))$mo + 1 as.numeric(substring("1979-12-20", 6, 7)) as.numeric(factor(months(as.Date("1979-12-20"), abbrev = TRUE), levels = month.abb)) See R News 4/1 Help Desk article for more on dates.