Merge three different columns into a date in R

前端 未结 4 779
梦毁少年i
梦毁少年i 2020-12-08 16:38

Right now, I am having 3 separate columns as year, month, and day in a data file in R. How do I merge these three columns into just one column and make R understand that it

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 17:12

    Since your year, month and day types are numerical the best function to use is the make_date function from the lubridate package. The tidyverse style solution is therefore

    library(tidyverse)
    library(lubridate)
    
    data %>%
      mutate(date = make_date(year, month, day))
    

提交回复
热议问题