Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

addxtabs

Add the cells of two or more xtab objects


Description

Adds the counts in corresponding cells of xtab objects

Usage

addxtabs(x)

Arguments

x

A list containing two or more return values from xtab.

Details

addxtabs adds the counts in the cells of two or more xtab objects by matching the row and column names. All of the xtab objects in the list will usually contain counts of the same response options, although some options may be missing in some tables. This often occurs when respondents do not have to complete all of the responses (e.g. "for up to three occasions ...").

This function facilitates calculating the total counts in crosstabulations that arise from multiple responses for the options. See the example.

Value

The number of valid values or the length of the object.

Author(s)

Jim Lemon

See Also

Examples

# Assume that respondents are asked to record the location and quantity for
 # three occasions of drinking, and for each occasion the fields are named
 # "drinks" and "loc"
 drinkloc<-data.frame(drinks1=sample(c("1-2","3-5","6+"),100,TRUE),
  loc1=sample(c("Meal at home","Restaurant","Party","Pub"),100,TRUE),
  drinks2=sample(c("1-2","3-5","6+"),100,TRUE),
  loc2=sample(c("Meal at home","Restaurant","Party","Pub"),100,TRUE),
  drinks3=sample(c("1-2","3-5"),100,TRUE),
  loc3=sample(c("Meal at home","Restaurant","Party"),100,TRUE))
 # notice how two options have been left out in drink3 and loc3
 # create the list of xtab objects
 dltablist<-list()
 dltablist[[1]]<-xtab(loc1~drinks1,drinkloc)
 dltablist[[2]]<-xtab(loc2~drinks2,drinkloc)
 dltablist[[3]]<-xtab(loc3~drinks3,drinkloc)
 # now sum the corresponding cells
 addxtabs(dltablist)

prettyR

Pretty Descriptive Stats

v2.2-3
GPL (>= 2)
Authors
Jim Lemon <drjimlemon@gmail.com>, Philippe Grosjean <phgrosjean@sciviews.org>
Initial release
2019-04-08

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.