delim.xtab: Format a crosstabulation

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Format a 2D crosstabulation from xtab

Usage

1
2
 delim.xtab(x,pct=c("row","column","cell"),coltot=TRUE,rowtot=TRUE,
  ndec=1,delim="\t",interdigitate=TRUE,label=deparse(substitute(x)))

Arguments

x

An object of class xtab.

pct

Whether and how to calculate percentages.

coltot,rowtot

Whether to add the marginal totals.

ndec

The number of decimal places for percentages.

delim

The delimiter to use between columns. Defaults to TAB.

interdigitate

Whether to place each column of percentages next to its row of counts.

label

A label to be displayed before the table.

Details

delim.xtab formats a crosstabulation in a manner similar to those produced by commercial spreadsheets, with a column of counts followed by a column of percentages. If interdigitate is FALSE, the percentages will be displayed separately.

delim.xtab will only process one 2D xtab object at a time.

To format only the counts, set pct to NA.

The intended use of delim.xtab is producing tables that can be imported into most word processors. If a table is output to an HTML or text document formatted with TAB characters, the output can be copied and pasted into the word processor document and then converted to a table.

Value

nil

Author(s)

Jim Lemon

See Also

xtab

Examples

1
2
3
4
5
6
7
 alpha1<-sample(LETTERS[1:3],50,TRUE)
 alpha2<-sample(LETTERS[1:2],50,TRUE)
 alphas<-data.frame(alpha1,alpha2)
 alphatab<-xtab(alpha1~alpha2,alphas)
 delim.xtab(alphatab,pct="row",interdigitate=TRUE)
 delim.xtab(alphatab,pct="column",interdigitate=TRUE)
 delim.xtab(alphatab,pct="cell",interdigitate=TRUE)

Example output

Crosstabulation of alpha1 by alpha2 
	alpha2
alpha1      A      B
A     13     11     24
   54.17  45.83      -
   44.83  52.38  48.00

B     13      4     17
   76.47  23.53      -
   44.83  19.05  34.00

C      3      6      9
   33.33  66.67      -
   10.34  28.57  18.00

      29     21     50
      58     42    100
alphatab

	A	B	Total
A 	13	11	24
B 	13	4	17
C 	3	6	9
Total 	29	21	50
 
alphatab

	A	%	B	%	Total	%
A 	13	54.2%	11	45.8%	24	100%
B 	13	76.5%	4	23.5%	17	100%
C 	3	33.3%	6	66.7%	9	100%
Total 	29	58%	21	42%	50	100%
 
alphatab

	A	B	Total
A 	13	11	24
B 	13	4	17
C 	3	6	9
Total 	29	21	50
 
alphatab

	A	%	B	%	Total	%
A 	13	44.8%	11	52.4%	24	48%
B 	13	44.8%	4	19%	17	34%
C 	3	10.3%	6	28.6%	9	18%
Total 	29	100%	21	100%	50	100%
 
alphatab

	A	B	Total
A 	13	11	24
B 	13	4	17
C 	3	6	9
Total 	29	21	50
 
alphatab

	A	%	B	%	Total	%
A 	13	26%	11	22%	24	48%
B 	13	26%	4	8%	17	34%
C 	3	6%	6	12%	9	18%
Total 	29	58%	21	42%	50	100%
 

prettyR documentation built on May 2, 2019, 2:16 a.m.

Related to delim.xtab in prettyR...