[R] expanding factor with NA

Thomas W Blackwell tblackw at umich.edu
Mon Oct 27 21:08:01 CET 2003


Perhaps a much simpler method (just thought of it) would be to set

options(na.action="na.pass")

before you start.  Or use  na.action=na.pass()  as an argument in
the call to  model.frame(), since that's where the problem begins.
See  help("na.omit"),  help("model.frame").

-  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Mon, 27 Oct 2003, J.R. Lockwood wrote:

> I have a factor (with "n" observations and "k" levels), with only
> "nobs" < n of the observations not missing.  I would like to produce a
> (n x k) model matrix with treatment contrasts for this factor, with
> rows of NAs placeholding the missing observations.  If I use
> model.matrix() I get back a (nobs x k) matrix.  Is there an easy way
> to get the (n x k) without carrying along a row ID and merging?
> Thanks.
>
> J.R. Lockwood
> 412-683-2300 x4941
> lockwood at rand.org
> http://www.rand.org/methodology/stat/members/lockwood/




More information about the R-help mailing list