Have lubridate subtraction return only a numeric value

后端 未结 3 1943
有刺的猬
有刺的猬 2020-12-17 10:34

I have one variable called Started which is the date on which human subjects enrolled in a study and another variable called dos1 which is the date

相关标签:
3条回答
  • 2020-12-17 11:01

    That's definitely a bug in lubridate. I've made an error report and will fix it for version 0.1:

    http://github.com/hadley/lubridate/issues#issue/75

    Thanks for bringing it to my attention.

    0 讨论(0)
  • 2020-12-17 11:08

    As noted in R - lubridate - Convert Period into numeric counting months the intended lubridate method here would be time_length

    time_length(syrrupan$Started-syrrupan$dos1, unit="days")
    
    0 讨论(0)
  • 2020-12-17 11:15

    You could try using difftime instead, ie:

    difftime(syrrupan$Started,syrrupan$dos1,units="days")
    

    Note that this will give you an object of class difftime, if you want a numeric vector, wrap an as.numeric around it. Note also that you can't choose months as an option for units, but you should really stick with a time unit that has a fixed length.

    0 讨论(0)
提交回复
热议问题