# NOT RUN {
# simple vector
data(efc)
frq(efc$e42dep)
# with grouped data frames, in a pipe
library(dplyr)
efc %>%
group_by(e16sex, c172code) %>%
frq(e42dep)
# show only categories with a minimal amount of frequencies
frq(mtcars$gear)
frq(mtcars$gear, min.frq = 10)
frq(mtcars$gear, min.frq = 15)
# with select-helpers: all variables from the COPE-Index
# (which all have a "cop" in their name)
frq(efc, contains("cop"))
# all variables from column "c161sex" to column "c175empl"
frq(efc, c161sex:c175empl)
# for non-labelled data, variable name is printed,
# and "label" column is removed from output
data(iris)
frq(iris, Species)
# also works on grouped data frames
efc %>%
group_by(c172code) %>%
frq(is.na(nur_pst))
# group variables with large range and with weights
efc$weights <- abs(rnorm(n = nrow(efc), mean = 1, sd = .5))
frq(efc, c160age, auto.grp = 5, weights = weights)
# different weight options
frq(efc, c172code, weights = weights)
frq(efc, c172code, weights = "weights")
frq(efc, c172code, weights = efc$weights)
frq(efc$c172code, weights = efc$weights)
# group string values
dummy <- efc[1:50, 3, drop = FALSE]
dummy$words <- sample(
c("Hello", "Helo", "Hole", "Apple", "Ape",
"New", "Old", "System", "Systemic"),
size = nrow(dummy),
replace = TRUE
)
frq(dummy)
frq(dummy, grp.strings = 2)
#### other expressions than variables
# logical conditions
frq(mtcars, cyl ==6)
frq(efc, is.na(nur_pst), contains("cop"))
iris %>%
frq(starts_with("Petal"), Sepal.Length > 5)
# computation of variables "on the fly"
frq(mtcars, (gear + carb) / cyl)
# crosstables
set.seed(123)
d <- data.frame(
var_x = sample(letters[1:3], size = 30, replace = TRUE),
var_y = sample(1:2, size = 30, replace = TRUE),
var_z = sample(LETTERS[8:10], size = 30, replace = TRUE)
)
table(d$var_x, d$var_z)
frq(d, paste0(var_x, var_z))
frq(d, paste0(var_x, var_y, var_z))
# }
Run the code above in your browser using DataLab