Mfactors is a package designed to make factors less painful. It consists of four main functions:
#install.packages("devtools") devtools::install_github("lmguzman/MelissaFactors") library(Mfactors)
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()
Is the equivalent from dplyr for count. It tally's up the different categories on a factor.
freq_out(iris$Species)
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') levels(factor(x)) levels(fac_as_is(x))
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) str(character_reading) factor_reading <- fread_csv(tf, check.factor = FALSE) str(factor_reading)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.