Skip to content
Prev 274801 / 398513 Next

Detect and replace omitted data

Prompted by David's xtabs() suggestion, one way to do what I think the
OP wants is to
 * define day and unit as factors whose levels comprise the full range
of desired values;
 * use xtabs();
 * return the result as a data frame.
Something like

x <- data.frame( day = factor(rep(c(4, 6), each = 8), levels = 4:6),
                 unit = factor(c(1:8, seq(2,16,2)), levels = 1:16),
                 value = floor(rnorm(16,25,10)) )
as.data.frame(with(x, xtabs(value ~ unit + day)))

HTH,
Dennis

On Tue, Oct 18, 2011 at 11:33 AM, David Winsemius
<dwinsemius at comcast.net> wrote: