
This function computes a frequency table with absolute and percentage frequencies for one or more than one variable.
freq(data, ..., print = c("no", "all", "perc", "v.perc"), freq = TRUE,
split = FALSE, labels = TRUE, val.col = FALSE, round = 3, exclude = 15,
digits = 2, as.na = NULL, write = NULL, append = TRUE, check = TRUE,
output = TRUE)
Returns an object of class misty.object
, which is a list with following
entries:
call
function call
type
type of analysis
data
data frame used for the current analysis
args
specification of function arguments
result
list with result tables, i.e., freq
for absolute
frequencies, perc
for percentages, and v.perc
for valid percentages
a vector, factor, or data frame.
an expression indicating the variable names in data
,
e.g., freq(dat, x1, x2, x3)
. Note that the operators
.
, +
, -
, ~
, :
, ::
,
and !
can also be used to select variables, see 'Details'
in the df.subset
function.
a character string indicating which percentage(s) to be
printed on the console, i.e., no percentages ("no"
),
all percentages ("all"
), percentage frequencies
("print"
), and valid percentage frequencies
("v.perc"
). Default setting when specifying one
variable is print = "all"
, while default
setting when specifying more than one variable is print = "no"
unless split = TRUE
.
logical: if TRUE
(default), absolute frequencies will
be shown on the console.
logical: if TRUE
, output table is split by variables
when specifying more than one variable in ...
.
logical: if TRUE
(default), labels for the factor
levels will be used.
logical: if TRUE
, values are shown in the columns,
variables in the rows.
an integer value indicating the number of decimal places to be used for rounding numeric variables.
an integer value indicating the maximum number of unique
values for variables to be included in the analysis when
specifying more than one variable i.e.,
variables with the number of unique values exceeding
exclude
will be excluded from the analysis. It is
also possible to specify exclude = FALSE
to include
all variables in the analysis.
an integer value indicating the number of decimal places to be used for displaying percentages.
a numeric vector indicating user-defined missing values,
i.e. these values are converted to NA
before
conducting the analysis.
a character string naming a file for writing the output into
either a text file with file extension ".txt"
(e.g.,
"Output.txt"
) or Excel file with file extension
".xlsx"
(e.g., "Output.xlsx"
). If the file
name does not contain any file extension, an Excel file will
be written.
logical: if TRUE
(default), output will be appended
to an existing text file with extension .txt
specified
in write
, if FALSE
existing text file will be
overwritten.
logical: if TRUE
(default), argument specification is checked.
logical: if TRUE
(default), output is shown on the console.
Takuya Yanagida takuya.yanagida@univie.ac.at
By default, the function displays the absolute and percentage frequencies when
specifying one variable, while the function displays only the absolute frequencies
when more than one variable is specified. The function displays valid percentage
frequencies only in the presence of missing values and excludes variables with
all values missing from the analysis. Note that it is possible to mix numeric
variables, factors, and character variables in the data frame specified in the
argument data
. By default, numeric variables are rounded to three digits
before computing the frequency table.
Becker, R. A., Chambers, J. M., & Wilks, A. R. (1988). The New S Language. Wadsworth & Brooks/Cole.
write.result
, crosstab
, descript
,
multilevel.descript
, na.descript
.
# Example 1: Frequency table for 'cyl'
freq(mtcars, cyl)
# Alternative specification without using the '...' argument
freq(mtcars$cyl)
# Example 2: Frequency table, values shown in columns
freq(mtcars, cyl, val.col = TRUE)
# Example 3: Frequency table, use 3 digit for displaying percentages
freq(mtcars, cyl, digits = 3)
# Example 4: Frequency table for 'cyl', 'gear', and 'carb'
freq(mtcars, cyl, gear, carb)
# Alternative specification without using the '...' argument
freq(mtcars[, c("cyl", "gear", "carb")])
# Example 5: Frequency table, with percentage frequencies
freq(mtcars, cyl, gear, carb, print = "all")
# Example 6: Frequency table, split output table
freq(mtcars, cyl, gear, carb, split = TRUE)
# Example 7: Frequency table, exclude variables with more than 5 unique values
freq(mtcars, exclude = 5)
if (FALSE) {
# Example 8a: Write Results into a text file
freq(mtcars, cyl, gear, carb, split = TRUE, write = "Frequencies.txt")
# Example 8b: Write Results into a Excel file
freq(mtcars, cyl, gear, carb, split = TRUE, write = "Frequencies.xlsx")}
Run the code above in your browser using DataLab