subtable.Rd
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.
subtable(data, cols, freqvar = "Freq", keep.zero = FALSE, allfactor = FALSE, return.type = class(data))
data | The |
---|---|
cols | An ordered integer vector containing the indices of the colums to keep. |
freqvar | Optional name of a frequency variable in |
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 |
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.
A data.frame
including a "Freq"
variable.
#> Type Sat Freq #> Tower :3 Low :4 Min. : 64.00 #> Apartment:3 Medium:4 1st Qu.: 77.75 #> Atrium :3 High :4 Median :100.00 #> Terrace :3 Mean :140.08 #> 3rd Qu.:194.00 #> Max. :302.00#> Var1 Var4 Freq #> 2 A4 D6 76 #> 9 A4 D7 324 #> 15 A3 D1 1991 #> 18 A3 D2 1203 #> 19 A3 D4 451 #> 21 A3 D3 405 #> 22 A3 D5 1440 #> 23 A10 D11 261 #> 25 A10 D9 661 #> 27 A10 D10 839 #> 28 A10 D8 543 #> 34 A8 D11 305 #> 36 A8 D9 734 #> 38 A8 D10 1097 #> 39 A8 D8 610 #> 48 A2 D1 2526 #> 51 A2 D2 1482 #> 52 A2 D4 588 #> 54 A2 D3 451 #> 55 A2 D5 1810 #> 57 A6 D6 180 #> 64 A6 D7 863 #> 67 A9 D11 369 #> 69 A9 D9 925 #> 71 A9 D10 1282 #> 72 A9 D8 798 #> 81 A1 D1 795 #> 84 A1 D2 475 #> 85 A1 D4 202 #> 87 A1 D3 145 #> 88 A1 D5 576 #> 89 A11 D11 83 #> 91 A11 D9 194 #> 93 A11 D10 297 #> 94 A11 D8 179 #> 100 A7 D11 503 #> 102 A7 D9 1200 #> 104 A7 D10 1716 #> 105 A7 D8 1034 #> 112 A5 D6 579 #> 119 A5 D7 3141