Learn R Programming

extracat (version 1.6-3)

subtable: data.frame reduction

Description

Reduces a data.frame into a frequency table with prespecified entries. Uses a modified version of the count function which also accepts weights. Zero-entries can be included or excluded and the variables can be coerced into factors if necessary.

Usage

subtable(data, cols, freqvar = NULL, 
		keep.zero = FALSE, allfactor = FALSE, return.type = class(data))

Arguments

data
The data.frame to reduce.
cols
An ordered integer vector containing the indices of the colums to keep.
freqvar
Optional name of a frequency variable in V. If dset contains a variable called "Freq" (see ftable) it will be defined as frequency variable if freqvar is
keep.zero
A logical indicating whether to include zero-cases in the output.
allfactor
A logical indicating whether to convert all variables into factor variables. Integer variables will be applied a fitting (non-lexicographic) level order.
return.type
The function is able to convert the output to a data.frame or table. The default is to use the same type as the input had.

Value

  • A data.frame including a "Freq" variable.

Details

This function uses a modified version of count in order to provide the arguments keep.zero and allfactor and to be able to handle both raw datasets and datasets with a frequency variable.

Examples

Run this code
hs2 = subtable(housing,c(3,1))
summary(hs2)

Run the code above in your browser using DataLab