Learn R Programming

extracat (version 1.7-6)

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 = "Freq", 
		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.

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 count as a workhorse and offers additional arguments keep.zero and allfactor. Both raw datasets, datasets with a frequency variable and tables can be handled.

Examples

Run this code
# NOT RUN {
require(MASS)
hs2 = subtable(housing,c(3,1))
summary(hs2)

A <- arsim(33333,c(11,11,11,11),3)
subtable(A, c(1,4))

# }

Run the code above in your browser using DataLab