How to convert in both directions between year,month,day and dates in R?

后端 未结 3 1203
悲&欢浪女
悲&欢浪女 2021-01-02 01:34

How to convert between year,month,day and dates in R?

I know one can do this via strings, but I would prefer to avoid converting to strings, partly because maybe the

3条回答
  •  灰色年华
    2021-01-02 02:11

    I'm a bit late to the party, but one other way to convert from integers to date is the lubridate::make_date function. See the example below from R for Data Science:

    library(lubridate)
    library(nycflights13)
    library(tidyverse)
    
    a <- flights %>%
      mutate(date = make_date(year, month, day))
    

提交回复
热议问题