prop.table divides every element by the matrix total, not its colSums:
> m <- matrix(1:4, 2) > m [,1] [,2] [1,] 1 3 [2,] 2 4 > prop.table(m) [,1] [,2] [1,] 0.1 0.3 [2,] 0.2 0.4 m/rowSums(m) divides every row by its rowSum: > m/rowSums(m) [,1] [,2] [1,] 0.2500000 0.7500000 [2,] 0.3333333 0.6666667 To divide every element by its colSum: > t(t(m)/rowSums(t(m))) [,1] [,2] [1,] 0.3333333 0.4285714 [2,] 0.6666667 0.5714286 Hope this helps. Spencer On 11/28/2010 12:55 PM, casperyc wrote:
In that case, there are values>1, which is clearly not what I wanted. Thanks. I think I should use prop.table
______________________________________________ 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.