Home > Net >  Convert from CHR to DATE in R
Convert from CHR to DATE in R

Time:11-05

Hi I have a date column called 'date' in format 2021-11-02. I need to change this from CHR to DATE in order that I can work with it in date format (filters etc). The below throws no error message but doesn't seem to convert to date, can anyone please advise.

    Table %>%
    mutate(Table, date= as.Date(date, format= "%Y-%m-%d")

CodePudding user response:

There are some errors in your code. Try this one:

Table %>%
mutate(date2 = as.Date(date, format= "%Y-%m-%d"))

CodePudding user response:

If your date format is in YYYY-MM-DD (default ISO 8601), as.Date() does not need the format argument.

Table %>% dplyr::mutate(dateConverted = as.Date(date))
  •  Tags:  
  • r
  • Related