Aye <- sample(c("Yes", "Si", "Oui"), 177, replace = TRUE)
( A1 <- table(Aye) )
Bee <- sample(c("Hum", "Buzz"), 177, replace = TRUE)
( A2 <- table(Aye, Bee) )
## 1-D table
# Add sums to margin
margins(A1)
# Add sums to margin of proportions table
margins(prop.table(A1))
## 2-D table
# Add sums to all margins
margins(A2)
# Add sums to end of rows (row totals)
margins(A2,margin=1)
# Add sums to end of columns (column totals)
margins(A2,margin=2)
# Add sums to end of a row proportions table
A2.row <- prop.table(A2,margin=1)
margins(A2.row, margin=1)
# Add sums to end of a column proportions table
A2.col <- prop.table(A2,margin=2)
margins(A2.col,margin=2)
# Add sums to all margins of proportions table
A2.tbl <- prop.table(A2)
margins(A2.tbl)
Run the code above in your browser using DataLab