Convert date to month in full

Asked

Viewed 403 times

3

I have a table in r with a column with months in numerical format

data = c("01", "03", "03", "04", "05", "10", "12"))

I would like to convert in the abbreviations of the months. I found how to put the abbreviations in English but I can’t put them in Portuguese.

1 answer

4


Just use the function month package lubridate:

library(lubridate)

data = c("01", "03", "03", "04", "05", "10", "12")

month(as.numeric(data), 
      label = TRUE, 
      locale = "pt_BR")
## [1] Jan Mar Mar Abr Mai Out Dez
## 12 Levels: Jan < Fev < Mar < Abr < Mai < Jun < Jul < Ago < Set < Out < ... < Dez

Like data is a character vector, I needed to transform it to a numerical vector first.

The option locale = "pt_BR" precisely serves to create the abbreviations of the months in Brazilian Portuguese.

  • 1

    Note: in Portugal now the months are written with lowercase initial and locale = "pt_BR" uses this convention. There is no difference if it is locale = "pt_PT". The system is Ubuntu 19.10/R 3.6.2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.