Skip to content
Prev 49281 / 398498 Next

Design matrix not identity

On Wed, 12 May 2004, Patrik Waldmann wrote:

            
Eh?  You have to construct the factor, and nothing else.
Uwe was quite correct, and you were still too quick.

[Don't call an object after an R function. Let's use a sensible name like
`f'.]

f <- as.factor(c(1,1,2,2,3,3,3))
model.matrix(~ 0 + f)

or

diag(nlevels(f))[f,]

gives what you illustrate.

        
PLEASE do.