Generates a frequency table from a data frame, including number of records by a specified variable or variables in the data frame with optional totals and/or subtotals.
datFreq(
x,
xvar = NULL,
total = FALSE,
subtotal = FALSE,
subtotalcol = NULL,
savedata = FALSE,
savedata_opts = NULL,
gui = FALSE
)
Data frame or comma-delimited file (*.csv). The table with the variable(s).
String (vector).* The name of the variable(s) to summarize.
Logical. If TRUE, a row is added to bottom of table with a total for the whole table.
Logical. If TRUE, a row is added to bottom of each section for subtotals.
Logical. If subtotal=TRUE, the column(s) to generate subtotals.
Logical. If TRUE, writes output data to outfolder.
List. See help(savedata_options()) for a list of options. Only used when savedata = TRUE. If out_layer = NULL, default = 'datfreq'.
Logical. If TRUE, pop-up windows will appear for user-interface.
Data frame. The frequency table.
If savedata=TRUE, a comma-delimited file of the frequency table is written to the outfolder.
If no parameters, then user is prompted for input. If partial parameters, default parameter values are used.
# Set up data for example
tab <- data.frame(cbind(CONDCLASS = c(1, 1, 2, 1, 3, 3, 3, 1, 1, 1, 2, 1),
FORTYPCD = c(182, 184, 201, 221, 221, 184, 221, 182,
182, 201, 182, 221)))
# Frequency table with "FORTYPCD"
datFreq(x = tab,
xvar = "FORTYPCD")
#> FORTYPCD FREQ
#> 1 182 4
#> 2 184 2
#> 3 201 2
#> 4 221 4
# Frequency table with "CONDCLASS" and "FORTYPCD"
datFreq(x = tab,
xvar = c("CONDCLASS", "FORTYPCD"))
#> CONDCLASS FORTYPCD FREQ
#> 1 1 182 3
#> 2 1 184 1
#> 3 1 201 1
#> 4 1 221 2
#> 5 2 182 1
#> 6 2 201 1
#> 7 3 184 1
#> 8 3 221 2
# Frequency table with "CONDCLASS" and "FORTYPCD", adding total and subtotal
# rows
datFreq(x = tab,
xvar = c("CONDCLASS", "FORTYPCD"),
total = TRUE,
subtotal = TRUE)
#> CONDCLASS FORTYPCD FREQ
#> 1 1 182 3
#> 5 2 182 1
#> 3 Subtotal 4
#> 2 1 184 1
#> 7 3 184 1
#> 6 Subtotal 2
#> 31 1 201 1
#> 61 2 201 1
#> 9 Subtotal 2
#> 4 1 221 2
#> 8 3 221 2
#> 12 Subtotal 4
#> 13 Total 12
# Frequency table for WYtree, multiple variables, subtotal options
datFreq(x = FIESTA::WYtree,
xvar = c("SPGRPCD", "SPCD", "STATUSCD"),
subtotal = TRUE, subtotalcol = "SPCD")
#> SPGRPCD SPCD STATUSCD FREQ
#> 1 10 202 1 849
#> 2 10 202 2 381
#> 3 Subtotal 1230
#> 31 11 122 1 1066
#> 4 11 122 2 181
#> 6 Subtotal 1247
#> 5 12 19 1 2653
#> 61 12 19 2 874
#> 9 Subtotal 3527
#> 7 18 93 1 1586
#> 8 18 93 2 674
#> 12 Subtotal 2260
#> 91 18 96 1 12
#> 14 Subtotal 12
#> 10 21 108 1 4407
#> 11 21 108 2 2103
#> 17 Subtotal 6510
#> 121 23 65 1 277
#> 13 23 65 2 46
#> 20 Subtotal 323
#> 141 23 66 1 374
#> 15 23 66 2 48
#> 23 Subtotal 422
#> 16 23 106 1 1
#> 25 Subtotal 1
#> 171 24 101 1 674
#> 18 24 101 2 637
#> 28 Subtotal 1311
#> 19 24 113 1 253
#> 201 24 113 2 286
#> 311 Subtotal 539
#> 21 44 745 1 16
#> 22 44 745 2 1
#> 34 Subtotal 17
#> 231 44 746 1 537
#> 24 44 746 2 283
#> 37 Subtotal 820
#> 251 44 749 1 26
#> 26 44 749 2 3
#> 40 Subtotal 29
#> 27 47 313 1 9
#> 281 47 313 2 4
#> 43 Subtotal 13
#> 29 47 375 1 1
#> 30 47 375 2 1
#> 46 Subtotal 2
#> 312 47 544 1 11
#> 48 Subtotal 11
#> 32 47 823 1 87
#> 33 47 823 2 14
#> 51 Subtotal 101
#> 341 48 475 1 4
#> 35 48 475 2 1
#> 54 Subtotal 5