calculating number of days between 2 columns of dates in data frame

后端 未结 5 1468
轮回少年
轮回少年 2020-12-02 12:56

I have a data frame which has two columns of dates in the format yyyy/mm/dd. I am trying to calculate the number of days between these two dates for each observation within

5条回答
  •  醉酒成梦
    2020-12-02 13:42

    You need to use the as.Date formats correctly.

    Eg.

    x = '2012/07/25'
    xd = as.Date(x,'%Y/%m/%d')
    xd    # Prints "2012-07-25"
    

    R date formats are similary to *nix ones.

    Doing a typeof(xd) shows it as a double ie. days since 1970.

提交回复
热议问题