How to change dates from the American format y/m/d to d/m/y in an R dataframe?

Asked

Viewed 415 times

2

I have a dataframe where the dates are in American format and I would like to know how to transform this column to the Brazilian format day-month-year.

I tried the package lubridate and the function dmy, but for some reason it’s not running.

inserir a descrição da imagem aqui

1 answer

3

The function dmy converts dates into day/month/year format only. Note that the Date column has a time in addition to the date. Use the function dmy_hms, in which hms means hour, minute and second respectively.

  • All right Marcos,

  • To solve this problem I convert this column to date using: $Date <- as data. Date(data$Date) *** original <dttm>*** format and then I applied the dmy function of the lubricated package and it did not work, but I confess that I am not sure that the arguments are correct. Based on this information which script you would use to change this column to day-month-year format?

  • 1

    @Rogério Não use as.Date, do directly dados$Date <- mdy_hms(etc). And notice that there are functions dmy_hms, with first day and mdy_hms with month first. In your case it is month first.

Browser other questions tagged

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