
Last chance! 50% off unlimited learning
Sale ends in
split_var(x, groupcount, as.num = FALSE, val.labels = NULL, var.label = NULL, inclusive = FALSE, suffix = "_g")
x
should be split into.TRUE
, the recoded variable will
be returned as numeric vector. If FALSE
, a factor is returned.set_labels
).
If NULL
(default), no value labels will be set. Value labels
can also be directly defined in the recodes
-syntax, see
'Details'.set_label
). If NULL
(default), variable label attribute of x
will be used (if present).
If empty, variable label attributes will be removed.TRUE
, cut point value are included in
the preceeding group. This may be necessary if cutting a vector into
groups does not define proper ("equal sized") group sizes.
See 'Note' and 'Examples'.x
, if x
is a data frame. If x
is not a data
frame, this argument will be ignored. The default value to suffix
column names in a data frame depends on the function call:
rec()
) will be suffixed with "_r"
dicho()
) will be suffixed with "_d"
split_var()
) will be suffixed with "_g"
split_var
splits a variable into equal sized groups, where the
amount of groups depends on the groupcount
-argument. Thus,
this functions cuts
a variable into groups at the
specified quantiles
.
By contrast, group_var
recodes a variable into
groups, where groups have the same value range
(e.g., from 1-5, 6-10, 11-15 etc.).
group_var
to group variables into equal ranged groups,
or rec
to recode variables.
data(efc)
# non-grouped
table(efc$neg_c_7)
# split into 3 groups
table(split_var(efc$neg_c_7, 3))
# original
table(efc$e42dep)
# two groups, non-inclusive cut-point
# vector split leads to unequal group sizes
table(split_var(efc$e42dep, 2))
# two groups, inclusive cut-point
# group sizes are equal
table(split_var(efc$e42dep, 2, inclusive = TRUE))
Run the code above in your browser using DataLab