Focusing on R Essentials

Randy Pruim

Less Volume, More Creativity

Less Volume, More Creativity

A lot of times you end up putting in a lot more volume, because you are teaching fundamentals and you are teaching concepts that you need to put in, but you may not necessarily use because they are building blocks for other concepts and variations that will come off of that … In the offseason you have a chance to take a step back and tailor it more specifically towards your team and towards your players.“

Mike McCarthy, Head Coach, Green Bay Packers


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.

— Antoine de Saint-Exupery

The Most Important R Template


goal ( yyy ~ xxx , data = mydata )


The Most Important R Template


goal (  y  ~  x  , data = mydata )

The Most Important R Template


goal (  y  ~  x  , data = mydata , …)


Simpler version:

  • goal( ~ x, data = mydata )


Fancier version:

  • goal( y ~ x | z , data = mydata )


Unified version:

  • goal( formula , data = mydata )

The Two Questions


goal (  y  ~  x  , data = mydata )


What do you want R to do? (goal)

  • This determines the function to use


What must R know to do that?

  • This determines the inputs to the function
  • Must identify the variables and data frame

Graphical Summaries: One Variable

freqpolygon( ~age, data=HELPrct) 

plot of chunk unnamed-chunk-3

What is a Frequency Polygon?

plot of chunk unnamed-chunk-4

Graphical Summaries: One Variable

freqpolygon( ~age, data=HELPrct ) 
  histogram( ~age, data=HELPrct ) 
densityplot( ~age, data=HELPrct ) 
     bwplot( ~age, data=HELPrct ) 
     qqmath( ~age, data=HELPrct ) 

Graphical Summaries: Two Variables

xyplot( births ~ dayofyear, data=Births78) 

plot of chunk unnamed-chunk-6

Graphical Summaries

bwplot( age ~ substance, data=HELPrct) 

plot of chunk unnamed-chunk-7

Graphical Summaries

bwplot( substance ~ age, data=HELPrct)