knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

Installation

#install_github("zhamel/foo")
library(foo)

Usage

This package consists of 4 functions which hopefully can make your life easier when dealing with factors.

fbind()

Goal: Bind two factors together to get back a factor with the levels from both factors.

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

freq_out()

Goal: Create a data frame consisting of the levels of the factor and its frequency.

freq_out(iris$Species)

reorder_levels()

Goal: Reordering the levels based on frequency (from least to most)

reorder_levels(factor(c("a","a","b","c","c","c","c","d","d","d")))

factor_to_char()

Goal: Should your factor be a character instead? This function compares the length of the factor with the number of levels. If the length of the factor = # of levels of the factor, then factor_to_char() returns TRUE: maybe this shouldn't be a factor! Otherwise, if they are different, factor_to_char() returns FALSE: this time you may want to keep it as a factor!

factor_to_char(iris$Species)


zhamel/foo documentation built on May 4, 2019, 10:15 p.m.