Find the most repeated row in a matrix
问题 I have about 10000 replicates of a sample in a matrix. My matrix has 1000 rows and 6 columns. Numbers in the columns range from 0:58 depending on the sample. actual.prob <- c(.14, .14, .16, .13, .19, .24) million.rep <- replicate(10000, sample(1:6, 58, replace= T, actual.prob)) new.matrix <- matrix(nrow= 10000, ncol=6) for(i in 1:10000){ new.matrix[i,] <- as.vector(table(factor(million.rep[,i], levels=1:6))) } new.matrix[1:10,] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 3 7 11 11 11 15 [2,] 7 6 12 5