prop.table(x, margin = NULL)
x | a numeric matrix, a table, or an array. |
margin |
a vector of subscripts over which the margins are specified.
For example, if x is a matrix, margin=1 indicates rows
and margin=2 indicates columns.
Note that margin specifies the dimensions by which the entries of x
are scaled in the result.
If margin is NULL, all entries in x are scaled by the sum of x. |
x <- array(1:120, dim = c(3, 2, 4, 5)) prop.table(x, c(2, 3)) prop.table(x, 1) prop.table(x)prop.table(matrix(1:12, nrow = 3), 1) # [,1] [,2] [,3] [,4] # [1,] 0.04545455 0.1818182 0.3181818 0.4545455 # [2,] 0.07692308 0.1923077 0.3076923 0.4230769 # [3,] 0.10000000 0.2000000 0.3000000 0.4000000
prop.table(matrix(1:12, nrow = 3)) # [,1] [,2] [,3] [,4] # [1,] 0.01282051 0.05128205 0.08974359 0.1282051 # [2,] 0.02564103 0.06410256 0.10256410 0.1410256 # [3,] 0.03846154 0.07692308 0.11538462 0.1538462
prop.table(matrix(1:12, nrow = 3), c(1,2)) # [,1] [,2] [,3] [,4] # [1,] 1 1 1 1 # [2,] 1 1 1 1 # [3,] 1 1 1 1