This is the R script repository of the "Coding 3: Introduction to R" course of the 2025/2026 Spring term, part of the MSc in Business Analytics at CEU. In the previous years, most of these materials were part of the "Data Analysis 1a: Exploration" course that you can find in the 2015/2016 Winter, 2016/2017 Fall, 2017/2018 Fall, 2018/2019 Fall, 2023/2024 Winter, and 2024/2025 Winter branches.
3 x 200 mins on May 4, 11, and 18:
- 13:30 - 15:10 session 1
- 15:10 - 15:40 break
- 15:40 - 17:20 session 2
In-person at the Vienna campus (QS A-214).
Please find in the syllabus folder of this repository.
Please bring your own laptop* and make sure to install the below items before attending the first class:
- Join the Teams channel dedicated to the class at
[BA 2025] Coding 3: Introduction to Rwith thevahwzjkteam code - Install
Rfrom https://cran.r-project.org - Install
RStudio Desktop(Open Source License) from https://posit.co/download/rstudio-desktop/ - Enter the following commands in the R console (bottom left panel of RStudio) and make sure you see a plot in the bottom right panel and no errors in the R console:
install.packages('ggplot2')
library(ggplot2)
ggplot(diamonds) +
aes(x = price, fill = cut) +
geom_density(alpha = 0.5) + facet_wrap(~ color) +
xlab('') + ylab('') +
theme_bw() + theme('legend.position' = 'top') +
guides(fill = guide_legend(nrow = 1))Optional steps I highly suggest to do as well before attending the class if you plan to use git:
-
Register an account at https://github.com
-
Bookmark, watch or star this repository so that you can easily find it later
-
Install
gitfrom https://git-scm.com/ -
Verify in RStudio that you can see the path of the
gitexecutable binary in the Tools/Global Options menu's "Git/Svn" tab -- if not, then you might have to restart RStudio (if you installed git after starting RStudio) or installed git by not adding that to the PATH on Windows. Either way, browse the "git executable" manually (in somebinfolder look for theegitexecutable file). -
Create an RSA key (optionally with a passphrase for increased security -- that you have to enter every time you push and pull to and from GitHub). Copy the public key and add that to you SSH keys on your GitHub profile.
-
Create a new project choosing "version control", then "git" and paste the SSH version of the repo URL copied from GitHub in the pop-up -- now RStudio should be able to download the repo. If it asks you to accept GitHub's fingerprint, say "Yes".
-
If RStudio/git is complaining that you have to set your identity, click on the "Git" tab in the top-right panel, then click on the Gear icon and then "Shell" -- here you can set your username and e-mail address in the command line, so that RStudio/git integration can work. Use the following commands:
$ git config --global user.name "Your Name" $ git config --global user.email "Your e-mail address"
Close this window, commit, push changes, all set.
Find more resources in Jenny Bryan's "Happy Git and GitHub for the useR" tutorial if in doubt or contact me.
(*) If you may not be able to use your own laptop, there's a shared RStudio Server set up in AWS - including all the required R packages already installed for you. Look up the class Slack channel for how to access.
For the curious mind, this is how the shared RStudio Server was set up in AWS:
Click to expand ...
TODO 💪 Installing software similar toadd_cranapt_noble.sh:
# most recent R builds
sudo apt install --no-install-recommends software-properties-common dirmngr
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
sudo apt update && sudo apt upgrade
sudo apt install r-base
# apt builds of all CRAN packages
wget -q -O- https://eddelbuettel.github.io/r2u/assets/dirk_eddelbuettel_key.asc | sudo tee -a /etc/apt/trusted.gpg.d/cranapt_key.asc
echo "deb [arch=amd64] https://r2u.stat.illinois.edu/ubuntu noble main" | sudo tee -a /etc/apt/sources.list.d/cranapt.list
sudo apt update
# install some R packages
sudo apt install -y \
r-cran-ggplot2 r-cran-ggally r-cran-readxl \
r-cran-data.table \
r-cran-glue r-cran-logger \
r-cran-pairsd3 r-cran-ggally \
r-cran-maps r-cran-nycflights13 \
r-cran-png r-cran-rpart r-cran-partykit r-cran-randomforest r-cran-pander
# install RStudio IDE
sudo apt install -y gdebi-core
wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2026.04.0-526-amd64.deb
sudo gdebi rstudio-server-*.deb
# reverse proxy for SSL termination
sudo apt install -y caddy
cat <<EOF | sudo tee /etc/caddy/Caddyfile
r.de3.click {
reverse_proxy localhost:8787 {
transport http {
read_timeout 20d
}
# need to rewrite the Location header to remove the port number
# https://caddy.community/t/reverse-proxy-header-down-on-location-header-or-something-equivalent/13157/3
header_down Location ([^:]+://[^:]+(:[0-9]+)?/) ./
}
}
EOF
sudo systemctl restart caddy
💪 Creating users
secret <- 'something super secret' # e.g. digest::digest(runif(1), algo="sha1")
users <- c('list', 'of', 'users')
library(logger)
library(glue)
for (user in users) {
## remove invalid character
user <- sub('@.*', '', user)
user <- sub('-', '_', user)
user <- sub('.', '_', user, fixed = TRUE)
user <- tolower(user)
log_info('Creating {user}')
system(glue("sudo adduser --disabled-password --quiet --gecos '' {user}"))
log_info('Setting password for {user}')
system(glue("echo '{user}:{secret}' | sudo chpasswd")) # note the single quotes + placement of sudo
log_info('Adding {user} to sudo group')
system(glue('sudo adduser {user} sudo'))
}- General overview of the R ecosystem: slides
- Numbers, strings, vectors, constants, variables: [1.R](1.R#L1
- Functions: 1.R
- Basic plots: 1.R
- Basic stats: 1.R
- Intro to data frames: 1.R
- Introduction to data visualization with
ggplot2: 1.R
- Warm-up exercise and security reminder: 2.R
- MDS: 2.R
- Simpson's paradox: 2.R
- Intro to
data.table: 2.R
-
EDA warmup: 3.R
-
Modeling:
Use any publicly accessible dataset (preferably from the TidyTuesday projects at https://github.com/rfordatascience/tidytuesday, but if you don't feel creative, feel free to default to using the diamonds from the ggplot2 package) and do data transformations that seems useful, optionally merge external datasets, generate data visualizations that makes sense and are insightful, plus provide comments on those in plain English.
Submission: prepare an R markdown document that includes plain English text description of the dataset, problems/questions you analyzed, actual R code chunks (printing both the code and its output) loading the data, doing the analysis, comments and summary/conclusion of the results, and knit the Rmd to HTML, then upload both the Rmd and the HTML to Moodle before June 1, 2026 midnight (CET).
Required items:
- filtering rows using
data.table, - aggregating data using
data.table, - at least 7 plots using at least 3 different
ggplot2geoms (e.g. a scatterplot, boxplot, barchart etc.)
The above items with proper homework solutions from the first week will result in "B" grade.
For "A", please also work on the below extra items:
- merge datasets,
- apply a theme,
- define the axis and plot titles,
- use a color palette from <colorbrewer2.org>,
- use multiple geom layers on the same plot,
- publish your results on RPubs.com/Medium (look at the "Publish" option in the "File" menu).
File a GitHub ticket.