'Foofactors' is a homework package for stat 547 that helps manipulate factors. Here are some examples using the Iris dataframe and factor Species.

Bind two factors

Bind 2 factors together using the function fbind()

library(foofactors)
fbind(iris$Species[c(1, 51, 101)], PlantGrowth$group[c(1, 11, 21)])

Get the frequency of factor levels

Tabulate the levels in a factor using freq_out()

freq_out(iris$Species)

Test whether a factor should a factor or character using fctr_or_chr()

This test depends on whether the factor has more observations than levels: if the number of unique values is equal to the number of observations, the function returns FALSE, i.e. the factor should really be a character, as it's values aren't repeated even once.

fctr_or_chr(iris$Species)

nlevels(iris$Species)
length(iris$Species)
#See?

Reorders levels of a factor in descending order using reorder_factor()

This function reorders the levels of a factor in descending order, alphabetically. It will accept numeric/character/logical/factor variables.

levels(iris$Species)

reorder_factor(iris$Species)


Poush87/foofactors documentation built on May 8, 2019, 3:09 p.m.