The R Ecosystem

Matthias Bannert (KOF, ETH Zurich)
April 30th

Where to start?


“Motivation is key. And it's all you can do in a couple of hours. It's like showing fat kids how to loose weight. There are tons of ways to do it. None of them will probably loose significant weight during a 3 hour session, but you can show them it's fun loosing weight and everybody has to continue working on their own from there on.”

From a community discussion about proper R Introduction.

About this Course

  • learn strategies to solve empirical problems using R
  • every session: lecture part - applied part (bring your notebook along!)
  • exam: Solve task in reproducible manner using Rmarkdown (.Rmd)
  • What to expect in detail? see: Course Outline

Where is R located among stats tools?

  • R is a programming language (unlike SPSS)
  • Interpreted scripting language (like Python)

-> Interactivity and a comfortable IDE enable us to use R as applied statisticians, not as software developers.

R Studio is NOT R

  • Base R (Look and Feel: Platform Dependent)
  • Eclipse StatET (Eclipse with R Plugin)
  • R Studio

Where to Get Help?

Popular Ressources

Context Help

# ?function name
?mean
# function 'calls' without () are also telling
sd
function (x, na.rm = FALSE) 
sqrt(var(if (is.vector(x)) x else as.double(x), na.rm = na.rm))
<bytecode: 0x103f861b8>
<environment: namespace:stats>
# Arithmetic Operators are functions too
?"+"

Packages

  • 5291 available packages (March 12th): from regressions and factor analysis, to twitter mining, visualization and interfaces to other programs and languages …
  • install.packages(“packagename”)

A popular package: ggplot2

require(ggplot2)
nrow(movies)
[1] 58788
# movies is an example dataset, it's just a data.frame
# with movie ratings
# just add more layers to the plot
m <- ggplot(movies, aes(x = rating))
m <- m + geom_histogram(binwidth = 0.5)
m <- m + aes(y = ..density..)
m + facet_grid(Action ~ Comedy)

A popular package: ggplot2

plot of chunk unnamed-chunk-3

Reproducible Documents With R

  • use the knitr package: .Rmd, .Rnw
  • no copy & pasting of tables and figures
  • seamless updates when new data becomes available

html, .rtf, .tex, .md, .pdf can be created using R.

Interactive Apps with Shiny / Shiny Server

Shiny is an application server for R web apps. Write R Code, Shiny generates interactive apps for you. You have to know hardly any HTML / CSS or even Javascript to build web applications.