freq | R Documentation |
This function computes a frequency table with absolute and percentage frequencies for one or more than one variable. By default, the function displays the absolute and percentage frequencies when specifying one variable, while the function displays only the absolute frequencies when specifying 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)
data |
a vector, factor, or data frame. |
... |
an expression indicating the variable names in |
print |
a character string indicating which percentage(s) to be
printed on the console, i.e., no percentages ( |
freq |
logical: if |
split |
logical: if |
labels |
logical: if |
val.col |
logical: if |
round |
an integer value indicating the number of decimal places to be used for rounding numeric variables. |
exclude |
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
|
digits |
an integer value indicating the number of decimal places to be used for displaying percentages. |
as.na |
a numeric vector indicating user-defined missing values,
i.e. these values are converted to |
write |
a character string naming a file for writing the output into
either a text file with file extension |
append |
logical: if |
check |
logical: if |
output |
logical: if |
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.
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 |
data frame with absolute frequencies and percentages or
list with result tables, i.e., |
Takuya Yanagida takuya.yanagida@univie.ac.at
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)
## Not run:
# 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")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.