table-operations {gRbase} | R Documentation |
For a contingency table in array form, compute the sum of table entries for a given index (i.e. a marginal table) or find the slice of the table defined by specific margins being at a specific level.
tableMargin(x, margin) tableSlice(x, margin, level, impose) tableOp(t1, t2, op = "*") tablePerm(a, perm, resize = TRUE)
x, t1, t2, a |
An array |
margin |
An index, either numerical or character |
level |
A value, either numerical or character |
impose |
Possible value used to fill up a slice to give it full dimension |
op |
Either "*" or "/" |
perm |
The subscript permutation vector, which must be a permutation of the integers 1:n, where n is the number of dimensions of a OR a permutation of the dimension names of a. The default is to reverse the order of the dimensions. A permutation of the dimensions of a. |
resize |
A flag indicating whether the vector should be resized as well as having its elements reordered. |
tableMargin: tableMargin is analogous to margin.table except that margin can be given both as array indices or as variable names
tableSlice: If the table x has dimensions Z,U,V where V has levels 1 and 2 then tableSlice can extract the slice of x (in this case a 2-way table) defined by e.g. U=2. Setting impose=1000 implies that a 3-way table is returned with the U=2 slice in the right place and the U=1-slice consisting of 1000 in each cell.
tableOp: If t1 has dimnames A and B and t2 has dimnames B and C then tableOp(t1,t2) will return a table (an array) with dimnames A, B and C containing the product.
tablePerm: A wrapper for aperm, but tablePerm accepts dimnames in addition to indices.
See examples below.
A table.
Søren Højsgaard
data(HairEyeColor) tableMargin(HairEyeColor, "Hair") tableMargin(HairEyeColor, 1) tableMargin(HairEyeColor, c("Hair","Eye")) tableMargin(HairEyeColor, c(1,2)) tableSlice(HairEyeColor, "Sex","Male") tableSlice(HairEyeColor, 3,1) tableSlice(HairEyeColor, "Sex","Male", impose=1000) tableSlice(HairEyeColor, 3,1, impose=1000) t1 <- array(1:4, dim=c(2,2), dimnames=list(gender=c('male','female'),answer=c('yes','no'))) t2 <- array(1:4+10, dim=c(2,2), dimnames=list(answer=c('yes','no'),category=c(1,2))) tableOp(t1,t2, "*") tableOp(t1,t2, "/")