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

This is a factors package for STAT 545.

Here's how to use the Mfactors package.

Mfactors is a package designed to make factors less painful. It consists of four main functions:

Installation

#install.packages("devtools")
devtools::install_github("lmguzman/MelissaFactors")
library(Mfactors)

Usage

fbind

fbind() makes sure that the levels of the two factors are also binded together.

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

freq_out

freq_out() Is the equivalent from dplyr for count. It tally's up the different categories on a factor.

freq_out(iris$Species)

fac_as_is

fac_as_is() creates a factor, but it leaves the levels as they appear on the data and not in alphabetical order.

x <- c('candy', 'wont', 'make', 'me', 'sick')

check out the levels

levels(factor(x))
levels(fac_as_is(x))

fread_csv

fread_csv() reads a csv but checks all columns that are imported as factors. If the number of levels in the factor is equal to the length of the column, then it becomes a character type. Othewise is left as a factor. All of the arguments passed onto read.csv() are available on fread_csv() plus an extra argument to check the factor.

tenletters <- factor(letters[1:10])
tf <- tempfile()
write.csv(tenletters, tf)

character_reading <- fread_csv(tf, check.factor = TRUE)

factor_reading <- fread_csv(tf, check.factor = FALSE)

Compare the structure when check.factor is TRUE or FALSE

str(character_reading)
str(factor_reading)


lmguzman/MelissaFactors documentation built on May 21, 2019, 7:35 a.m.