unGroup | R Documentation |
Mix values of factor variable levels in (approximately) equal proportions to disrupt existing structure of levels, i.e. "ungroup".
unGroup(gr, n = NULL, base = "new_group_", new.names = NULL)
gr |
A vector indicating original groups. |
n |
Number of new groups. If |
base |
Base for names of new groups. Default is |
new.names |
Labels for new groups. If value is not |
Default number of new groups n
is equal to number of factor levels.
n = nlevels(gr)
. If NA's exist, they are treated as one
more additional group thus n = nlevels(gr) + 1
.
A vertor with new groups, which are a mix of proportionally distributed (ungrouped) original groups.
Vilmantas Gegzna
Other spHelper utilities:
IQR_outliers()
,
expr2text()
,
mad_outliers()
,
rmExpr()
,
sd_outliers()
,
subt()
,
uncall()
gr <- Scores2$gr
# -------------------------------------------------------
set.seed(1)
newGr <- unGroup(gr)
table(gr,newGr, useNA = "ifany")
# NA's are treated as an additional level ---------------
gr[5:10] <- NA
set.seed(1)
newGr <- unGroup(gr)
table(gr,newGr, useNA = "ifany")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.