I am trying to come up with a design matrix / dummy variable matrix which is unbalanced (in the context of a simulation project). The unequal observations are currently simulated as follows:
set.seed(1)
n_i <- as.matrix(round(runif(3,min=0, max=5)))
n_i
[,1]
[1,] 1
[2,] 2
[3,] 3
I would like to create a matrix of the following form based on the simulated sample sizes above:
des <- cbind(c(1,rep(0,5)),c(0,rep(1,2),rep(0,3)), c(rep(0,3),rep(1,3)))
Are there simple ways of doing this that don’t involve complicated for-loops? Needless to add that my real data set runs into 1000s of observations.
Would appreciate any help on this.
Try this one