Overview

This package is designed to simplify working with factors. It consists of three functions as outlined below.

Package Installation

One must first install and load the package.

#install.packages("FirstPackage")
devtools::install_github("jeffbone/First-Package")

Data to be Used in Examples

fruit <- c("Apples","Oranges","Bananas")
fruit <- as.factor(fruit)
gourd <- c("Potatoes","Yams","Squash")
gourd <- as.factor(gourd)
veg <- c("Carrots","Bell Peppers","Celery")
veg <- as.factor(veg)

Example of fbind

fbind takes two factors and puts them together into one. The input is two factors and the output is one factor. For example,

#example 1
fbind(fruit,gourd)

#example 2
fbind(veg,fruit)

#example 3
fbind(1,2) #won't run if inputs are not factors

Example of freq_out

freq_out creates a frequency table for a factor. The input must be a factor and the output is a tbl data frame. For example,

#example 1
fruit_sample <- sample(fruit,20,rep=TRUE)
fruit_sample
freq_out(fruit_sample)

#example 2
veg_sample <- sample(veg,20,rep=TRUE)
combined_fruit_veg <- fbind(fruit_sample,veg_sample)
freq_out(combined_fruit_veg)

#example 3
freq_out(c(1,1,1,1)) #won't run if input is not a factor

Example of reorder_factor

reorder_factor reorders the levels of a factor based on frequency. The input is a factor and the output is the same factor with reordered levels. For example,

#example 1
veg_sample <- sample(veg,20,rep=TRUE)
veg_sample
reorder_factor(veg_sample)

#example 2
reorder_factor(gourd) #doesn't reorder if all levels have same number

#example 3
reorder_factor(c(1,2,3)) #doesn't run if input is not a factor


jeffbone/First-Package documentation built on May 19, 2019, 1:48 a.m.