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

library(magrittr)
library(modellingTools)

modellingTools: Common Tools for Data Preparation and Modelling

Programming in R is delightful. Data analysis in R can be a bit challenging at times. modellingTools was created to provide a formal outlet for useful personal tools I have developed in order to make data preparation and analysis simpler using R. I found that too often, when attempting to get to know my dataset using R, I fell in to the following pattern:

After a year or so of this, I started getting smart about it: every time I modified a base function in some useful way, I would save it in a function. But soon, I found myself following a new pattern:

Finally I bought Hadley Wickham's book, and figured now's as good as ever to learn how to build a package. This solves my above problems because:

A fourth benefit is: you get to use the package too! Thank you for doing so, and please let me know via email (alex@alexstringer.ca) if you have any bugs for me to fix, or suggestions for new features.

Example: Frequency distribution of a variable

Getting the frequency distribution of a variable in base R is actually surprisingly unpleasant. The table function requires vectors as input:

data(CO2)
table(CO2$conc)

As you can see, the output also isn't that pretty. You can clean up the code using with,

with(CO2,table(conc))

or if you're really cutting-edge, with the %$% operator from the magrittr package:

# install.packages("magrittr")
library(magrittr)
CO2 %$% table(conc)

All this for a basic frequency distribution. And don't even think about doing it for a continuous variable:

CO2 %$% table(uptake)

Talk about hard to read, and that's only 84 observations!

Try proc_freq, from the modellingTools package. Advantages:

We can do

proc_freq(CO2,"conc")

as well as

proc_freq(CO2,"uptake")

The real value comes from

proc_freq(CO2,"uptake",bins = 4)

Installation Instructions

modellingTools is now on CRAN, so you can get the package by typing

install.packages("modellingTools")

Since I'm actively developing the package, it may just be better to use the development version:

install.packages("devtools")
devtools::install_github("awstringer/modellingTools")

After that, attach the package

library(modellingTools)

and you're good to go!

Overview

For a detailed overview and introduction to using the package and what it does, see the vignette. Check out the github page for all the code as well.



awstringer/modellingTools documentation built on May 11, 2019, 4:11 p.m.