Skip to content
Prev 39349 / 398500 Next

expanding factor with NA

Strangely (to me), just passing na.action=na.pass to model.matrix doesn't
work:
(Intercept) fb fc
1            1  0  0
2            1  1  0
3            1  0  1
4            1  0  0
5            1 NA NA
6            1  0  1
7            1  0  0
8            1 NA NA
9            1  0  1
10           1  0  0
11           1  1  0
12           1  0  1
13           1 NA NA
14           1  1  0
15           1  0  1
attr(,"assign")
[1] 0 1 1
attr(,"contrasts")
attr(,"contrasts")$f
[1] "contr.treatment"
(Intercept) fb fc
1            1  0  0
2            1  1  0
3            1  0  1
4            1  0  0
6            1  0  1
7            1  0  0
9            1  0  1
10           1  0  0
11           1  1  0
12           1  0  1
14           1  1  0
15           1  0  1
attr(,"assign")
[1] 0 1 1
attr(,"contrasts")
attr(,"contrasts")$f
[1] "contr.treatment"

[OK, it's not so strange: na.action is not a documented argument for
model.matrix, and the call to model.frame in model.matrix.default does not
have ..., but shouldn't it?]

Andy