Suppose we have a data.frame :
> df <- data.frame(A = c('a','a','b','c','c','b','a'), B = c('d','e','e','e','f','f','g'))
On printing the values we'll get:
> df
A B
1 a d
2 a e
3 b e
4 c e
5 c f
6 b f
7 a g
On applying model.matrix
, it gives:
> d <- model.matrix(~.,df)
> d
(Intercept) Ab Ac Be Bf Bg
1 1 0 0 0 0 0
2 1 0 0 1 0 0
3 1 1 0 1 0 0
4 1 0 1 1 0 0
5 1 0 1 0 1 0
6 1 1 0 0 1 0
7 1 0 0 0 0 1
Now, as we could see in the factor df$A
, there are 3 unique characters i.e ( a, b, c). But, in its equivalent model.matrix we have Ab
, Ac
. Similarly, in case of df$B
, Bd
is missing.
So, My question is how can we get all the columns in a model.matrix
representation, if i'm neglecting the Intercept
?