Merge three different columns into a date in R

前端 未结 4 774
梦毁少年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 16:58

    Try:

      df$date <- as.Date(with(df, paste(year, mon, day,sep="-")), "%Y-%m-%d")
       df$date
      #[1] "1947-01-01" "1947-04-01" "1947-07-01" "1947-10-01" "1948-01-01"
      #[6] "1948-04-01"
    

提交回复
热议问题