Calculating days per month between interval of two dates

前端 未结 2 581
无人及你
无人及你 2021-01-18 17:53

I have a set of events that each have a start and end date, but they take place over the scope of a number of months. I would like to create a table that shows the number of

2条回答
  •  甜味超标
    2021-01-18 18:27

    As DjSol already pointed out in his comment, you can just subtract two dates to get the number of days:

    event_start_date <- as.Date("23/10/2012", "%d/%m/%Y")
    event_end_date   <- as.Date("07/02/2013", "%d/%m/%Y")
    as.numeric(event_end_date - event_start_date)
    

    Is that what you want? I have the feeling that you might have more of a problem to get the start and end date in such a format so you can easily subtract them because you mention a loop. If so, however, I guess we need more details on how your actual data looks.

提交回复
热议问题