'Foofactors' is a homework package for stat 547 that helps manipulate factors. Here are some examples using the Iris dataframe and factor Species.
Bind 2 factors together using the function fbind()
library(foofactors) fbind(iris$Species[c(1, 51, 101)], PlantGrowth$group[c(1, 11, 21)])
Tabulate the levels in a factor using freq_out()
freq_out(iris$Species)
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?
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.