Convert multiple columns to dates with lubridate and dplyr

后端 未结 1 1560
礼貌的吻别
礼貌的吻别 2021-01-20 18:42

I\'m looking for a straightforward way to convert all of the variables in a data frame which begin with \'date\' to dates using lubridate::dmy() (they are curre

相关标签:
1条回答
  • 2021-01-20 19:19

    You can use mutate_at()

    library(dplyr)
    library(lubridate)
    
    df <- mutate_at(df, vars(starts_with("date")), funs(dmy))
    

    or use mutate_if to mutate all date columns to dmy. Using is.Date from lubridate.

    df  <- mutate_if(df, is.Date, funs(dmy))
    
    0 讨论(0)
提交回复
热议问题