Skip to content
Prev 274806 / 398506 Next

Detect and replace omitted data

On Oct 18, 2011, at 2:53 PM, Dennis Murphy wrote:

            
Oh, ... sometimes I'm "slow". Dennis' code has it's virtues, but  
sometimes people want to avoid factors. Could also create a zero- 
numeric-matrix to fill the interiors and rbind to the analysis matrix  
just in the data= input to xtabs:

  zeroes <- cbind(day =seq( min(day), max(day), by=1),
                 unit=seq(min(unit), max(unit), by=1),
                 value=0)   # ignore warning

xtabs(value~day+unit, data=rbind(x, zeroes) )
    unit
day  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
   4 25 34  3 25 38 18 19 33  0  0  0  0  0  0  0  0
   5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
   6  0 22  0 42  0 37  0  4  0 12  0 31  0 17  0 28