Need Help creating a matrix in r

#1
I need to create a matrix similar to:
(1,0,0) for 3 rows
(1,1,0) for 3 rows
(1,0,1) for 3 rows

I guess you could say I need help learning rep( ) in the matrix function. Thanks for your help.
 

hlsmith

Not a robit
#3
Probably a better way to do it like you referenced.

Code:
A <- matrix(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1), nrow=9)              # number of rows 
A
 

Dason

Ambassador to the humans
#4
I have a feeling this is just a step in a larger process. Can you explain your overall goal. I'll give some code that does what you ask in a relatively roundabout way but I think gets more at what you really want to do.
Code:
model.matrix(~rep(letters[1:3], each=3))
 
#5
This is what i used. Thanks for the help.

Code:
A <- matrix(cbind(rep(1,6),rep(0,6),rep(0,6),rep(0,6)),nrow=6,ncol=4)
B <- matrix(cbind(rep(1,6),rep(1,6),rep(0,6),rep(0,6)),nrow=6,ncol=4)
C <- matrix(cbind(rep(1,6),rep(0,6),rep(1,6),rep(0,6)),nrow=6,ncol=4)
D <- matrix(cbind(rep(1,6),rep(0,6),rep(0,6),rep(1,6)),nrow=6,ncol=4)

X <- matrix(rbind(A,B,C,D),ncol=4)