"Most likely reason is that the number of unique values in the rows of habs is not the same."
Yes, I think that is the problem, thank you. How would I write the code to include 0s in the matrix, ie, I want to have a record of when 1, 2, or 3 does not get sampled, to come up with a frequency of each value for each nn (which in this case is 5) I tried 'factor' but what ends up happening is that the matrix gets reduced to zero after a couple of iterations. habs=t(apply(habs, 1, function(x) table(factor(x, levels = 1:3)))) -- View this message in context: http://r.789695.n4.nabble.com/non-numeric-argument-to-binary-operator-tp3598160p3598563.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.