questionr (version 0.7.4)

tabs: Weighted Crossresult

Description

Generate table with multiple weighted crossresult (full sample is first column). kable(), which is found in library(knitr), is recommended for use with RMarkdown.

Usage

tabs(
  df,
  x,
  y,
  type = "percent",
  percent = FALSE,
  weight = NULL,
  normwt = FALSE,
  na.rm = TRUE,
  na.show = FALSE,
  exclude = NULL,
  digits = 1
)

Arguments

df

A data.frame that contains x and (optionally) y and weight.

x

variable name (found in df). tabs(my.data, x = 'q1').

y

one (or more) variable names. tabs(my.data, x = 'q1', y = c('sex', 'job')).

type

'percent' (default ranges 0-100), 'proportion', or 'counts' (type of table returned).

percent

if TRUE, add a percent sign after the values when printing

weight

variable name for weight (found in df).

normwt

if TRUE, normalize weights so that the total weighted count is the same as the unweighted one

na.rm

if TRUE, remove NA values before computation

na.show

if TRUE, show NA count in table output

exclude

values to remove from x and y. To exclude NA, use na.rm argument.

digits

Number of digits to display; ?format.proptab for formatting details.

Details

tabs calls wtd.table on `x` and, as applicable, each variable named by `y`.

Examples

Run this code
# NOT RUN {
data(hdv2003) 
tabs(hdv2003, x = "relig", y = c("qualif", "trav.imp"), weight = "poids")
result <- tabs(hdv2003, x = "relig", y = c("qualif", "trav.imp"), type = "counts")
format(result, digits = 3)
# library(knitr)
# xt <- tabs(hdv2003, x = "relig", y = c("qualif", "trav.imp"), weight = "poids")
# kable(format(xt))                        # to use with RMarkdown...

# }

Run the code above in your browser using DataCamp Workspace