I have one mutation count matrix, like "counts". This matrix has the column names V1, V2, ..., Vi, ... Vn, where not all "i" are. Thus, he can jump, for example, V1, V2, V5. In addition, most columns have 0.
I need to create a sum matrix called an βanswerβ, where the element i, j is the sum of the number of number counters for both i and j. In element i, I just show the number of samples in i.
Here you can quickly configure data. I already have the correct dimensional matrix installed in my code called "answer". Thus, I need to automate the last few rows where I fill the matrix.
counts <- matrix(data = c(0,2,0,5,0,6,0), nrow = 1, ncol = 7, dimnames=list("",c("V1","V2","V3","V4","V5","V6","V7"))) answer <- matrix(data =0, nrow = 3, ncol = 3, dimnames = list(c("V2","V4","V6"),c("V2","V4","V6"))) answer[1,1] <- 2 answer[1,2] <- 7 answer[1,3] <- 8 answer[2,1] <- 7 answer[2,2] <- 5 answer[2,3] <- 11 answer[3,1] <- 8 answer[3,2] <- 11 answer[3,3] <- 6
I understand that I can do this with two nested loops, but of course there should be a better way, no? Thanks!