Skip to content
Prev 198926 / 398506 Next

design matrix construction question

How about something like this?

dd$xf <- (dd$x > 0) + 0
model.matrix(~ z:xf - 1, dd)
  za:xf zb:xf
1     1     0
2     1     0
3     1     0
4     0     0
5     0     0
6     0     0
7     0     1
8     0     1
attr(,"assign")
[1] 1 1
attr(,"contrasts")
attr(,"contrasts")$z
[1] "contr.treatment"