split_var(x, groupcount, as.num = FALSE, val.labels = NULL,
var.label = NULL, inclusive = FALSE)
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.set_label
). If NULL
(default), variable label attribute of x
will be used (if present).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'.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 all values within a group have the same range
(e.g., from 1-5, 6-10, 11-15 etc.).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