freq | R Documentation |
This function computes a frequency table with absolute and percentage frequencies for one or more than one variable.
freq(..., data = NULL, 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)
... |
a vector, factor, matrix or data frame. Alternatively, an
expression indicating the variable names in |
data |
a data frame when specifying one or more variables in the
argument |
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 in |
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 |
By default, the function displays the absolute and percentage frequencies when
specifying one variable in the argument ...
, 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 ...
. 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 |
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 1a: Frequency table for 'cyl'
freq(mtcars$cyl)
# Example 1b: Alternative specification using the 'data' argument
freq(cyl, data = mtcars)
# 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 4a: Frequency table for 'cyl', 'gear', and 'carb'
freq(mtcars[, c("cyl", "gear", "carb")])
# Example 4b: Alternative specification using the 'data' argument
freq(cyl, gear, carb, data = mtcars)
# Example 5: Frequency table, with percentage frequencies
freq(mtcars[, c("cyl", "gear", "carb")], print = "all")
# Example 6: Frequency table, split output table
freq(mtcars[, c("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[, c("cyl", "gear", "carb")], split = TRUE, write = "Frequencies.txt")
# Example 8b: Write results into an Excel file
freq(mtcars[, c("cyl", "gear", "carb")], split = TRUE, write = "Frequencies.xlsx")
result <- freq(mtcars[, c("cyl", "gear", "carb")], split = TRUE, output = FALSE)
write.result(result, "Frequencies.xlsx")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.