列的最佳组合,假设我有2000列的大型矩阵(matrix_1)。每个单元格的值为0或1.我想要找到10列的最佳组合。最佳组合给出每行非0值的最大数量。因此,它基本上提供了最大的找到一个矩阵
sum (apply (matrix_2, 1, function(x) any(x == 1)))
我不能去通过所有可能的组合,因为它是计算量太大(有2.758988e + 26)。有什么建议么?
举一个例子借此矩阵具有4行,我一次只
mat <- matrix (c(1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0), nrow = 4, byrow = FALSE)
mat
# combination of columns 2 and 3 is best: 3 rows with at least a single 1 value
sum (apply (mat[, c(2, 3)], 1, function(x) any (x == 1)))
# combination of columns 1 and 2 is worse: 2 rows with at least a single 1 value
sum (apply (mat[, c(1, 2)], 1, function(x) any (x == 1)))
在你的矩阵有多少行? – CPak
100-200行。取决于应用程序通过'colSums(COL)' –
你不能为了你的列并选择前10名?我问,因为我不是100%确定你想要什么,这有助于我更好地了解你在找什么。 – CPak