Skip to content
Prev 32023 / 398506 Next

number of patients in a hospital on a given date

how about this:

x <- data.frame(patid=c("pat1", "pat2"), adm.date = c("15.03.2002","16.03.2002"),dis.date=c("18.03.2002", "17.03.2002"))
x[,2:3] <- apply(x[,2:3], MARGIN=2, FUN=strptime, format="%d.%m.%Y")
alldays <- c("2002-03-14","2002-03-15","2002-03-16","2002-03-17","2002-03-18","2002-03-19")
tmp <- table(unlist(apply(x,
                          1,
                          function(y){
                            beg <- match(y[2],alldays)
                            end <- match(y[3],alldays)
                            alldays[beg:end]})))
nulldays <- alldays[match(alldays,names(tmp),nomatch=0)==0]
out <- rbind(data.frame(days=c(names(tmp),nulldays),freq=c(as.numeric(tmp),rep(0,length(nulldays)))))
out[order(out$days),]

        days freq
5 2002-03-14    0
1 2002-03-15    1
2 2002-03-16    2
3 2002-03-17    2
4 2002-03-18    1
6 2002-03-19    0

tomy

RINNER Heinrich <H.RINNER at tirol.gv.at> writes:

  
    
Message-ID: <7evfwd3937.fsf@rembrandt.fdm.uni-freiburg.de>
In-Reply-To: <C4D44AB4CB62D311BA6500041202E886031EE204@xms1.tirol.gv.at> (RINNER Heinrich's message of "Wed, 14 May 2003 15:01:58 +0200")