0

I want insert two variables into a model.matrix, but I don't know how to do that

> k<-model.matrix(m2)
> dim(k)

[1] 475 28

k$township72<-rep(0,475)
Warning message:
In k$township72 <- rep(0, 475) : Coercing LHS to a list
Tommy Yu
  • 1,080
  • 3
  • 11
  • 30
  • Try replacing `$` with `[` ie. `k[,'township72'] <- rep(0,475)` or may be use `cbind` i..e `cbind(k, township72=rep(0,475))` – akrun May 31 '15 at 13:54
  • Still not working"> k[,'township72']<-rep(0,475) Error in `[<-`(`*tmp*`, , "township72", value = c(0, 0, 0, 0, 0, 0, 0, : subscript out of bounds" – Tommy Yu May 31 '15 at 13:58
  • Try the `cbind`, it should work. It worked with an example I created – akrun May 31 '15 at 13:58
  • 1
    Yeah, it works. Thank you very much! – Tommy Yu May 31 '15 at 14:01

0 Answers0