overflowers,
I have an issue to solve with regards to counting the patients:
- fulfilling certain criteria but at different point in time. To the problem which I am trying to solve, different points in time, are dates, but rounded to the last day of the month. As you can see, I have patients before 2011, those whose dates are in 2008, 2009, 2010. These, then shall be counted to 2011-01-31 date. With the other dates, from 2011 on wards, these shall be counted to the rounded date (last day of the month).
The criteria for a patient to be counted is:
- the patient was discharged and was diagnosed.
Here is an example:
I have id
ID = c(101, 102,103, 104, 105, 106, 107, 108, 109,110, 111, 112, 113, 114)
I have registration dates
Reg.date = as.POSIXct(c("2008-01-14", "2008-03-19", "2009-06-13", 
                        "2010-08-17", "2011-09-11", "2012-08-14",
                        "2013-09-21",   "2013-08-09", "2014-02-15", 
                        "2014-07-22",  "2015-03-13",  "2015-05-30" , 
                         "2017-01-26", "2017-01-01"))
I deducted date -Deduct.date- with NA values, this means the patients are still alive. Where there are dates, that means, the patients are discharged. The same with Diagnosis - the NA means the patient wasn#t diagnosed.
Deduct.date = as.POSIXct(c("2008-09-16 ", "2010-01-13", "2010-02-12", 
                           "2011-02-12",    NA,       "2012-02-12",
                           "2012-02-12",     NA,           NA,
                             NA,           "2014-04-12",   NA,
                             NA,          "2017-02-11" ))
Diagnosis = as.POSIXct(c("2008-05-11" , "2009-03-13", "2009-01-03",
                            NA,         NA,           NA,
                          "2011-04-05",   NA,           NA,
                          "2013-03-05",   NA,            NA,
                          NA))
df = data.frame(ID, Reg.date, Deduct.date)
I am looking to do this with tidyverse and lubridate. And the outcome can be given in a dataframe with counts for the rounded dates, with reference to the ones provided above.
 
    