
Last chance! 50% off unlimited learning
Sale ends in
frq(x, ..., sort.frq = c("none", "asc", "desc"), weight.by = NULL)
x
is
a data frame (and no vector) and only selected variables
from x
should be processed. You may also use functions like
:
or dplyr's select_helpers
.
The latter must be stated as formula (i.e. beginning with ~
).
See 'Examples' or package-vignette."none"
, so
categories are not sorted by frequency. Use "asc"
or
"desc"
for sorting categories ascending or descending order.NULL
, so no weights are used.x
.
flat_table
for labelled (proportional) tables.
library(haven)
# create labelled integer
x <- labelled(
c(1, 2, 1, 3, 4, 1),
c(Male = 1, Female = 2, Refused = 3, "N/A" = 4)
)
frq(x)
x <- labelled(
c(1:3, tagged_na("a", "c", "z"), 4:1, 2:3),
c("Agreement" = 1, "Disagreement" = 4, "First" = tagged_na("c"),
"Refused" = tagged_na("a"), "Not home" = tagged_na("z"))
)
frq(x)
# in a pipe
data(efc)
library(dplyr)
efc %>%
select(e42dep, e15relat, c172code) %>%
frq()
# or:
# frq(efc, e42dep, e15relat, c172code)
# with grouped data frames, in a pipe
efc %>%
group_by(e16sex, c172code) %>%
frq(e16sex, c172code, e42dep)
# 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)
Run the code above in your browser using DataLab