foofactors

This is the README for thefoofactorspackage, which is a toy package created for STAT547. It is not recommended for general use, so if you want to know more about dealing withfactor, you can downloadforcatspackage.

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

Overview

Thefoofactorspackage contains 7 functions to help users taking control of factors easier and less annoying.

Installation

devtools::install_github("Tangjiahui26/foofactors")

Usage

fbind()

fbind() combines two factors in a way that is more logical than c(a,b). The return value offbind()is also a factor.

library(foofactors)
a <- factor(c("character", "hits", "your", "eyeballs"))
b <- factor(c("but", "integer", "where it", "counts"))
c(a,b)
fbind(a, b)

freq_out()

set.seed(1234)
x <- factor(sample(letters[1:5], size = 100, replace = TRUE))

Thefreq_out()function returns a frequency table as a well-namedtbl_df:

freq_out(x)

detect_factors()

The function detect_factors() is used to check if some of the element of the factor are not unique. Otherwise, if all of the elements are unique, you probably should use it as character.

a <- factor(c("a","b","c")) ##Should be character
b <- factor(c("a","b","b")) ##Should be factor

detect_factors(a)
detect_factors(b)

check_factors()

If you want to check a dataframe for factors, you can usecheck_factors(). This functions will check if your dataframe contains any factors you don't want to use.

check_factors(iris)
check_factors(mtcars)

new_factor() and new_factor_rev()

The function new_factor() would like to set your factors to the order in which they appear in the data. In contrast, If you want the reverse order,new_factor_rev() can be used in your codes.

a <- factor(c("c","b","a"))
b <- factor(c("banana","apple","pear"))
levels(a)
new_factor(a)
levels(b)
new_factor(b)

Examples fornew_factor_rev():

new_factor_rev(a)
new_factor_rev(b)

new_reorder()

Sometimes we may want to change the order of factors, and instead order them in descending way. The functionnew_reorder()can help you to realize it.

a <- factor(c("a","b","c"))

levels(a)
levels(new_reorder(a))

Acknowledgements



Tangjiahui26/foofactors documentation built on May 18, 2019, 8:11 p.m.