n_cell: Frequency Cell FUN

Description Usage Arguments Details Author(s) Examples

View source: R/n_cell.R

Description

For calculating relative or absolute frequencies.

Usage

1
2
   n_cell(x, y, z, w, cell_ids, row_ids, col_ids, vnames, vars, n_min,
          digits=0, digits2=1, type="n")

Arguments

x

The x variable (can be easy 1:N if no missings)

y

NOT USED

z

NOT USED

w

Weights for x variable. Only if calculating weigted frequences.

cell_ids

Index vector for selecting values in cell.

row_ids

Index vector for selecting values in row.

col_ids

Index vector for selecting values in col.

vnames

NOT USED

vars

NOT USED

n_min

NOT USED

digits

Integer indicating the number of decimal places (N)

digits2

Integer indicating the number of decimal places (percent)

type

Type of frequencies, one of following.

  • n, Number in cell.

  • pct, Overall percentages.

  • pctn, Overall percentages and n.

  • rowpct, Percentages of rows.

  • colpct, Percentages of cols.

  • rowpctn, Percentages of rows and n.

  • colpctn, Percentages of cols and n.

  • all, Overall, row, col percentages.

Details

The function calculate frequencies for cell. If x has no missings the frequencies are independent from x.

Author(s)

ADES <[email protected]>

Examples

1
2
3
4
5
6
7
sex     <- factor(rbinom(1000, 1, 0.4),  labels=c('Men', 'Women'))
decades <- rbinom(1000, 3, 0.5)
decades <- factor(decades, labels=c('[35,45)','[45,55)','[55,65)','[65,75)'))
d<-data.frame(sex, decades)
tabular.ade(x_var='sex',  rows=c('sex',     'ALL'), rnames=c('Gender'),
                          cols=c('decades', 'ALL'), cnames=c('Age decades'),
            data=d, FUN=n_cell, , type="all")

Example output

Loading required package: xtable
Loading required package: Hmisc
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

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

    label, label<-

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

    format.pval, round.POSIXt, trunc.POSIXt, units

  1             2        3                               
1 ""            "Gender" ""                              
2 "Age decades" ""       "[35,45)"                       
3 ""            "Men"    "7.5% - 12.3% row - 67.6% col"  
4 ""            "Women"  "3.6% - 9.3% row - 32.4% col"   
5 ""            "Total"  "11.1% - 11.1% row - 100.0% col"
  4                                5                               
1 ""                               ""                              
2 "[45,55)"                        "[55,65)"                       
3 "21.5% - 35.1% row - 59.2% col"  "24.5% - 40.0% row - 61.3% col" 
4 "14.8% - 38.1% row - 40.8% col"  "15.5% - 39.9% row - 38.8% col" 
5 "36.3% - 36.3% row - 100.0% col" "40.0% - 40.0% row - 100.0% col"
  6                                7                                 
1 ""                               ""                                
2 "[65,75)"                        "Total"                           
3 "7.7% - 12.6% row - 61.1% col"   "61.2% - 100.0% row - 61.2% col"  
4 "4.9% - 12.6% row - 38.9% col"   "38.8% - 100.0% row - 38.8% col"  
5 "12.6% - 12.6% row - 100.0% col" "100.0% - 100.0% row - 100.0% col"
attr(,"start cell")
[1] 3 3

etable documentation built on May 29, 2017, 9:45 a.m.