I want to find frequency of a matrix by their column. for example for matrix x below
x <- matrix(c(rep(1:4,3),rep(2:5,2)),4,5)
x
[,1] [,2] [,3] [,4] [,5]
[1,] 1 1 1 2 2
[2,] 2 2 2 3 3
[3,] 3 3 3 4 4
[4,] 4 4 4 5 5
now how can find frequency of each unique column and create a matrix that each column is a unique column of x and the last row is added as the frequency of it in matrix x
#freqmatrix
[,1] [,2]
[,1] 1 2
[,2] 2 3
[,3] 3 4
[,4] 4 5
[,5] 3 2
What’s your end goal, exactly? In other words, how are you going to work with this data further? If it’s just tabulation, doesn’t
paste()get you to the answer?If you do want
Var1separated, you can useread.csv()on that column.Or, if you prefer to transpose your output: