Table: One-Dimensional Table of Frequences and/or Percentages

Description Usage Arguments Value Examples

Description

Table is a generic function that produces a table of counts or weighted counts and/or the corresponding percentages of an atomic vector, factor or "item.vector" object. This function is intended for use with Aggregate or genTable. The "item.vector" method is the workhorse of codebook.

Usage

1
2
3
4
5
6
7
8
9
## S4 method for signature 'atomic'
Table(x,weights=NULL,counts=TRUE,percentage=FALSE,...)
## S4 method for signature 'factor'
Table(x,weights=NULL,counts=TRUE,percentage=FALSE,...)
## S4 method for signature 'item.vector'
Table(x,weights=NULL,counts=TRUE,percentage=(style=="codebook"),
              style=c("table","codebook","nolabels"),
              include.missings=(style=="codebook"),
              missing.marker=if(style=="codebook") "M" else "*",...)

Arguments

x

an atomic vector, factor or "item.vector" object

counts

logical value, should the table contain counts?

percentage

logical value, should the table contain percentages? Either the counts or the percentage arguments or both should be TRUE.

style

character string, the style of the names or rownames of the table.

weights

a numeric vector of weights of the same length as x.

include.missings

a logical value; should missing values included into the table?

missing.marker

a character string, used to mark missing values in the table (row)names.

...

other, currently ignored arguments.

Value

The atomic vector and factor methods return either a vector of counts or vector of percentages or a matrix of counts and percentages. The same applies to the "item.vector" vector method unless include.missing=TRUE and percentage=TRUE, in which case total percentages and percentages of valid values are given.

Examples

1
2
3
4
5
6
7
  with(as.data.frame(UCBAdmissions),Table(Admit,Freq))
  Aggregate(Table(Admit,Freq)~.,data=UCBAdmissions)

  A <- sample(c(1:5,9),size=100,replace=TRUE)
  labels(A) <- c(a=1,b=2,c=3,d=4,e=5,dk=9)
  missing.values(A) <- 9
  Table(A,percentage=TRUE)

Example output

Loading required package: lattice
Loading required package: MASS

Attaching package: 'memisc'

The following objects are masked from 'package:stats':

    contr.sum, contr.treatment, contrasts

The following object is masked from 'package:base':

    as.array

Admitted Rejected 
    1755     2771 
   Gender Dept Admitted Rejected
1    Male    A      512      313
3  Female    A       89       19
5    Male    B      353      207
7  Female    B       17        8
9    Male    C      120      205
11 Female    C      202      391
13   Male    D      138      279
15 Female    D      131      244
17   Male    E       53      138
19 Female    E       94      299
21   Male    F       22      351
23 Female    F       24      317
    Counts  Percent
a 23.00000 26.74419
b 20.00000 23.25581
c 11.00000 12.79070
d 15.00000 17.44186
e 17.00000 19.76744

memisc documentation built on May 2, 2019, 5:45 p.m.

Related to Table in memisc...