Question

R question:I would like to use a data-frame with x coordinates in one column and y coordinates in the second column to fill in a matrix. The matrix would then be used by heatmap() to create a dendrogram.

Here is an example:

> head(S1)
  DB_num AD_num
1      2   8060
2      7   3553
3      8   4812
4     13   7745
5     24   3315
6     24   6012

I would also need to know how to make the matrix if possible. The data-frame's max value is 15,490 so I guess the matrix would have to be 15,490 by 15,490. Since the matrix is so large I guess it would have to be filled with NA rather than zeros?

Was it helpful?

Solution

mtx <- matrix(NA, 15490 , 15,490)
mtx[ as.matrix(S1) ] <- 1   # two column matrix can be used to index

You will need to have sufficient machine resources if this is your strategy. It's not going to fit inside most 4GB devices, or it may fit but then run out of memory if you try to do anything with it. Filling with NA will not conserve space unless you use sparse matrices from pkg::Matrix. I continue to believe you need statistical advice more than you need coding advice, even though you appear to have deleted an earlier version of this question. I do see this as a sensible way forward to build a classification structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top