Calculate number of days between two dates in r

后端 未结 4 1659
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 23:22

I need to calculate the number of days elapsed between multiple dates in two ways and then output those results to new columns: i) number of days that has elapsed as compare

4条回答
  •  余生分开走
    2020-12-17 23:36

    For the first part:

    DATA = data.frame((c("7/8/2013",  "8/1/2013", "8/30/2013", "10/23/2013","12/16/2013", "12/16/2015")))
    names(DATA)[1] = "V1"
    date = as.Date(DATA$V1, format="%m/%d/%Y")
    print(date-date[1])
    

    Result:

    [1]   0  24  53 107 161 891
    

    For second part - simply use a for loop

提交回复
热议问题