Let's say I have the following in 12x3 matrix
m<-rbind(c(0,7,0),c(1,1,5),c(6,1,1),c(1,3,-3),c(1,3,-3),c(1,1,5),
c(0,7,0),c(1,1,5),c(1,1,5),-c(0,7,0),c(1,1,5),c(1,3,-3))
and would like count the number of times each row-vector occurs. What do I do?
I have tried to use table()
, but table()
only counts the elements.
You could convert each row to a concatenated string and then use table.
m <- apply(m, 1, function(x) paste(x, collapse=" "))
table(m)
m
0 -7 0 0 7 0 1 1 5 1 3 -3 6 1 1
1 2 5 3 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With