table_values_multi: A table_values wrapper for multiple choice data

Description Usage Arguments Details Value Examples

View source: R/table_values_multi.R

Description

Takes a dataset and returns a constructed data.frame of counts for multiple choice data collected in a number of columns as text rather than Yes/No or TRUE/FALSE.

Usage

1
2
3
table_values_multi(data, vars, var.order = c(), type, strata = NULL,
  strata.names = NULL, strata.count = TRUE, overall = TRUE, count = "n",
  round = 3, messages = TRUE)

Arguments

data

Dataset to generate table from

vars

A vector of the columns (in string form) to be used to generate the table from

var.order

Optional. A vector of the values to use for the multiple choice. Anything found which does not match the list will be ignored. If messages = TRUE then a message will discuss the differences.

type

A vector of the method to summarise the var

strata

A string of the column to used to stratify on

strata.names

Otional. A named vector of alternative strata names

strata.count

TRUE/FALSE for displaying strata counts at the top of each column

overall

TRUE/FALSE for including an overall column

count

"n","miss" or "none" providing the counts, missing values or omitting for each column for numeric variables

round

A value or vector for the number of significant figures to report the data to

messages

TRUE/FALSE report messages for missing row names in var.order

zeros

TRUE/FALSE report zeros (TRUE) or leave cell blank?

Details

Values labeled as "" or NA are ignored

Available methods and values for Type:

"st" count
"str" count/total
"stp" count (percent)
"strp" count/total (percent)

This function essentially itterates over all unique entries in the vars to generate an indicator variable for each one for each row. The grunt of the work is done using var[["option"]] = sapply(1:dim(data)[1], function(i) {max(data[i,vars] == "option", na.rm = TRUE)}). For more complex tables it may be easier to use this approach first and call table_values with other variables afterwards.

Note that column 2 is not removed in making this table so that it can be easily combined with other calls to table_values using rbind. If it is not to be combined this column will be empty so you may want to drop it.

Value

Returns a data.frame

Examples

1
2
3
4
data = data.frame(a=c("Yes","No","No",""),b=c("Yes","Please","No","Yes"), stringsAsFactors = FALSE)
vars = c("a","b")

table_values_multi(data,vars,type = "st")

csmoxford/prettyTables documentation built on May 14, 2019, 12:24 p.m.