I have an existing covariance matrix and I would like to convert it to become block diagonal based on which groups the individual columns belong to (e.g. 1st 2 rows/columns are group 1, next are group 2 etc.) Is there a simple way of doing this:
Below is an example of what I have:
m1 <- matrix(1:16, ncol=4, byrow=TRUE)
rownames(m1) <- colnames(m1 ) <- c('a', 'b', 'c', 'd')
a b c d
a 1 2 3 4
b 5 6 7 8
c 9 10 11 12
d 13 14 15 16
I have 2 groups:
Group 1: 'a', 'b'
Group 2: 'c', 'd'
and what I would like:
a b c d
a 1 2 0 0
b 5 6 0 0
c 0 0 11 12
d 0 0 15 16