# Addition
2 + 2
# Subtraction
5.432 - 34234
# Multiplication
33 * 42
# Division
3 / 42
# Power
2^2
# Combine operations
((2 + 2) * 5)^2Day 1 - Introduction to Data Analysis with R
Freie Universität Berlin - Theoretical Ecology
March 6, 2026
Whitespace does not matter
There are good practice rules however -> More on that later
RStudio will (often) tell you if something is incorrect
Store values under meaningful names to reuse them
The most basic data types in R:
Numeric: numbers like 1.243, -0.5, 42, 1e6
Logical: only two possible values TRUE and FALSE
Character: sequence of characters surrounded by quotes ("hello", "sample_1")
Vectors are a collections of values that are all of the same basic data type.
# 10 biggest cities in Europe
cities <- c("Istanbul", "Moscow", "London", "Saint Petersburg", "Berlin",
"Madrid", "Kyiv", "Rome", "Bucharest", "Paris")
population <- c(15.1e6, 12.5e6, 9e6, 5.4e6, 3.8e6,
3.2e6, 3e6, 2.8e6, 2.2e6, 2.1e6)
area_km2 <- c(2576, 2561, 1572, 1439, 891,
604, 839, 1285, 228, 105)Arithmetic operations work element by element:
Use square brackets [] to access specific elements from a vector.
Functions make multiple operations available under one command.
NA represents a missing value in R.
R doesn’t compute the mean if a value is missing.
How do we fix this? Let’s check the function help!
Access the help file of each function with ?functionName
radius <- 5c()v[3]v[1:4], v[c(1, 5)]function_name(input1, input2, ...)na.rm = TRUE in functions like mean()?function_nameTask (20 min)
R Basics: Variables, Vectors & Functions
Find the task description here
Selina Baldauf // Introduction R
Comments vs. Code
Everything that follows a
#is a comment