I have got a matrix of 96 rows and 42372 columns.
I am supposed to take the mode of first 4 rows in all columns and dump it as a first row in another matrix.
Then take mode of next four rows in all columns and dump it as a second row in another matrix.
And so on.
New matrix will be having 24 rows and 42372 columns.
I have written a function as below; SOURCE: Is there a built-in function for finding the mode?
GetMode <- function(x)
{
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
Output is the first matrix. (96 rows and 42372 columns)
Output2 is the new matrix. (24 rows and 42372 columns)
I am trying as of now as
output2[1,]<-GetMode(output[1:4,])
But it is printing mode for each row across all columns and printing it as a new row.