Lecture materials for an intensive one-day block course introducing data analysis with R, designed for first-year graduate students in economics (MEcon Program at the University of St.Gallen).
📦 GitHub Repository: github.com/umatter/R_intro
The course materials are available in English (en) and German (de) with Swiss orthography.
R_intro/
├── Makefile # Build system (multi-language)
├── README.md
├── Syllabus.md # Course description
│
├── materials/
│ ├── en/ # English materials
│ │ ├── notes/ # Lecture notes (source)
│ │ │ ├── 01_background_tools.Rmd
│ │ │ ├── 02_firststeps_concepts.Rmd
│ │ │ ├── 03_working_with_data.Rmd
│ │ │ ├── 04_probability_random_variation.Rmd
│ │ │ ├── 05_experiments_causal_thinking.Rmd
│ │ │ ├── 06_statistical_inference.Rmd
│ │ │ ├── html/ # Compiled HTML notes
│ │ │ └── pdf/ # Compiled PDF notes
│ │ │
│ │ ├── slides/ # Lecture slides (source)
│ │ │ ├── 01_introduction.Rmd
│ │ │ ├── 02_first_steps.Rmd
│ │ │ ├── 03_working_with_data.Rmd
│ │ │ ├── 04_probability.Rmd
│ │ │ ├── 05_experiments.Rmd
│ │ │ ├── 06_inference.Rmd
│ │ │ └── pdf/ # Compiled Beamer PDF slides
│ │ │
│ │ ├── R_code/ # Extracted R scripts from notes
│ │ └── solutions/ # Exercise solutions
│ │
│ ├── de/ # German materials (Swiss orthography)
│ │ ├── notes/ # Vorlesungsnotizen
│ │ │ ├── 01_hintergrund_werkzeuge.Rmd
│ │ │ ├── 02_erste_schritte_konzepte.Rmd
│ │ │ ├── 03_arbeiten_mit_daten.Rmd
│ │ │ ├── 04_wahrscheinlichkeit_zufallsvariation.Rmd
│ │ │ ├── 05_experimente_kausales_denken.Rmd
│ │ │ ├── 06_statistische_inferenz.Rmd
│ │ │ ├── html/
│ │ │ └── pdf/
│ │ │
│ │ ├── slides/ # Vorlesungsfolien
│ │ │ ├── 01_einfuehrung.Rmd
│ │ │ ├── 02_erste_schritte.Rmd
│ │ │ ├── 03_arbeiten_mit_daten.Rmd
│ │ │ ├── 04_wahrscheinlichkeit.Rmd
│ │ │ ├── 05_experimente.Rmd
│ │ │ ├── 06_inferenz.Rmd
│ │ │ └── pdf/
│ │ │
│ │ ├── R_code/ # Extrahierte R-Skripte
│ │ └── solutions/ # Übungslösungen
│ │
│ ├── img/ # Shared images (all languages)
│ └── references/ # Shared bibliography (R_intro.bib)
│
├── data/ # Sample datasets
│ ├── swiss.csv
│ ├── swiss.xlsx
│ └── swiss.sav
│
├── style/ # Style files (BFH corporate identity)
│ ├── notes_bfh.css # CSS for HTML notes
│ ├── beamer_preamble_bfh.tex # Beamer/Metropolis theme customization
│ ├── beamerthemeBFH.sty # BFH Beamer theme
│ └── beamercolorthemeBFH.sty # BFH color definitions
No prior knowledge of R or programming is expected. Exercises assume basic familiarity with statistics and econometrics.
- Why R? Why programming?
- The tools: R, RStudio, Posit Cloud
- R as a calculator, variables, vectors
- Basic programming: loops, conditionals, functions
- Data structures: vectors, lists, matrices, data frames
- Importing data (CSV, Excel, SPSS, STATA)
- Data visualization with ggplot2
- Basic regression analysis and stargazer tables
- Random experiments in R (
sample()) - Probability as long-run frequency (Law of Large Numbers)
- Sampling variation and sampling distributions
- The bootstrap: resampling to understand uncertainty
- Correlation vs. causation
- Confounding variables and spurious correlations
- Randomized experiments: the gold standard
- Simpson's paradox and the potential outcomes framework
- The logic of hypothesis testing
- Permutation tests for comparing means and proportions
- Bootstrap confidence intervals
- Chi-square tests for independence
- Connection between t-tests and regression
Run the setup script to install all dependencies:
./setup.shThis will check for R, optionally help install it, and install all required R packages.
R (required):
- macOS:
brew install ror download from CRAN - Ubuntu/Debian:
sudo apt install r-base r-base-dev - Windows: Download from CRAN
R packages (required):
install.packages(c("bookdown", "knitr", "rmarkdown", "ggplot2",
"readxl", "haven", "stargazer", "ctv", "gridExtra"))LaTeX (optional, for PDF output):
- Recommended: TinyTeX via R:
Rscript -e 'install.packages("tinytex"); tinytex::install_tinytex()' - macOS:
brew install --cask mactex - Ubuntu/Debian:
sudo apt install texlive-full latexmk - Windows: MiKTeX or TinyTeX
The project uses a Makefile for building. Run make help to see all options:
Usage: make [target]
Targets:
all Build everything (all languages)
en Build English materials only
de Build German materials only
notes Build all notes (HTML, PDF, R scripts)
slides Build all slides (Beamer PDF)
html Build HTML notes only
pdf Build PDF only (notes + slides)
rcode Extract R scripts only
clean Remove intermediate files
distclean Remove all generated files
list Show source and output files
help Show this help message
make # Build everything (both languages)
make en # Build English materials only
make de # Build German materials only
make -j4 # Build with 4 parallel jobs (faster)
make slides # Build only Beamer PDF slides (both languages)
make html # Build only HTML notes
make clean && make # Full rebuild| Language | Directory | Status |
|---|---|---|
| English | materials/en/ |
Complete |
| German (Swiss) | materials/de/ |
Complete |
German materials use Swiss orthography (e.g., "grosse" instead of "große", "weiss" instead of "weiß").
Contributions welcome! Please:
- Report issues or suggest enhancements via GitHub Issues
- Submit pull requests for improvements or new exercises
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.