r merge model.matrix with the dataset

20 views Asked by At

I have a dataset like this.

library(lme4)
data("sleepstudy")    
head(sleepstudy)

First I create a matrix of X values.

 X <- cbind(1, sleepstudy$Days)

Then I create a matrix Z

 Z <- model.matrix(~ 0 + Subject + Subject:Days, data = sleepstudy)

How do I attach the model.matrix Z with matrix Z , such that the two matrices or dataframes are merged in the right manner.

Thanks.

0

There are 0 answers