Hi
I have a matrix with 10000 columns and 400 rows. The values in the matrix are 1, 2, or 3
I want to calculate for each column the frequencies of 1, 2 and 3
Here a smaller matrix, with only 5 columns and 7 rows- to demonstrate the setup structure
matrix(sample(1:3, 35, replace=TRUE), nrow=7, ncol=5)
#
# [,1] [,2] [,3] [,4] [,5]
#[1,] 1 3 3 3 1
#[2,] 3 1 3 2 2
#[3,] 2 2 3 1 2
#[4,] 3 1 3 2 3
#[5,] 2 1 2 3 3
#[6,] 2 2 2 2 1
#[7,] 3 2 3 2 3
The results should be something like this :
# [,1] [,2] [,3] [,4] [,5]
#[1,] 1 3 0 1 2
#[2,] 3 3 2 4 2
#[3,] 3 1 5 2 3
I know table() and prop.table() functions - but thy works on single vector. I can run a loop over the columns. But, since it is a very big dataset, I prefer to avoid of using loops - if it possible.