R model.matrix and as.factor level of less

89 Views Asked by At

I would like to build two matrix with factor.

It works well for first serie but not the second. I don't understand, series have the same characteristics(dimension, format..) . But for the second dataset, i got one level less.

first.vec<-c(2,2,3,3,3,3,3,3,3,4,4,4,3,3,3,3,3,4,4,4,4,3,1,1,2,2,2,2,2,2,2,2,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,3,3,3,3,3,2,3,4,3,4,4,4,4,4,4,4,4,4,3,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,0,1,1,1,1,2,3,3,3,2,2,3,3,3,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,3,3,2,2,2,2,2,3,3,2,2,2,1,1,1,1,1,2,1,1,2,2,2,2,1,1,1,2,2,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,3,3,4,3,4,3,4,4,3,3,2,3,2,2,3,2,2,2,2,2,3,4,3,3,3,3,3,2,2,2,2,2,3,4,4,4,4,3,4,4,4,4,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,3,3,3,2,2,3,3,3,3,3,2,3,3,3,4,4,4,4,3,3,3,2,2,3,2,2,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,2,1)
    matrix.first=model.matrix(~as.factor(first.vec))


second.vec<-c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4)
 matrix.second=model.matrix(~as.factor(second.vec))

thank you so much for your help

0

There are 0 best solutions below