- R Documentation
- Tidyverse
- RStudio Cheatsheets
- R-Bloggers
- Stack Overflow
- Towards Data Science
- R for Data Science
Please prepare for the exercise by following these steps:
- Download and install
R
from here: https://cloud.r-project.org/ - Download and install
RStudio
from here: https://www.rstudio.com/products/rstudio/download/#download - Make sure that you can open RStudio and that it works by entering
sum(1, 1)
and pressingEnter ⏎
. You should see an output of2
.
Everything below will be covered during the exercise, but feel free to read ahead.
First of all, the goal for this course is not to teach you everything you will need to work with R. The goal here is to show you how some basics, give you an introduction to RStudio, and make you curious to explore by yourself. Depending on the wellness activity you choose, you will need different commands and approaches for the analysis. Therefore, we want to show you where to look for the answers and give you a glimpse into working with R. The goal is most definitely not to make you memorize some random commands or functions because...
🏆 The single most important skill you need to use R is knowing how to use a search engine well.
- Variables are usually in
snake_case
- Variable assignments look like this:
days_in_year <- 365
ordays_in_year = 365
- Function calls look like this:
f(x, y)
. Example:round(3.14158, digits = 2)
- To inspect a variable type
days_in_year
and pressEnter ⏎
- One important data structure is vectors, they look like this (for a string vector) (the
c
stands forcombine
):c('Han Solo', 'Chewbacca')
- Most commonly in our course, data is stored in
data.frame
s ortibble
s. Atibble
(ortbl_df
) is a modern reimagining of thedata.frame
, so fundamentally the same but better. - The pipe: Instead of calling functions like this
f(x, y)
, you can also use a so-called pipe and put the first function parameter in front of it like this:x %>% f(y)
. Example from above:3.14157 %>% round(digits = 2)
is the same asround(3.14157, digits = 2)
. Another example:5 %>% sum(7)
is the same assum(5, 7)
.