Convert multiple character columns to as.Date and time in R

后端 未结 1 672
陌清茗
陌清茗 2021-01-17 01:15

We have an arbitrary dataset, called df:

enter <- c("2017-01-01", "2018-02-02", "2018-03-03") 
guest <- c("Foxtrot&qu         


        
1条回答
  •  粉色の甜心
    2021-01-17 01:29

    You just need to tweak the arguments of mutate_at. Any additional arguments to as.Date are specified as arguments to mutate_at.

    df2 <- df %>% mutate_at(vars(enter,disposal,date), as.Date, format="%Y-%m-%d")
    

    The second part of your question has a similar solution.

    df2 <- df2 %>% mutate_at(vars(clock, rolex), function(x) chron(times. = x))
    

    0 讨论(0)
提交回复
热议问题