install.packages("tidyverse")Day 1 - Introduction to Data Analysis with R
Freie Universität Berlin - Theoretical Ecology
March 6, 2026
The tidyverse is an opinonated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures.
(www.tidyverse.org)
These are the main packages from the tidyverse that we will use:
Install the tidyverse once with:
Then load and attach the packages at the beginning of your script:
You can also install and load the tidyverse packages individually, but since we will use so many of them together, it’s easier to load and attach them together.
Where does R look for the file?
read_* functionsAll read_* functions take a path to the data file as a first argument:
read_*(“path/to/your/file”, …)
The read functions provide several options for non-perfect data.
Have a look at ?read_delim for all options.
Useful if your data is not a “perfect table”
Use skip to skip lines at the top of a file
Use col_names if your file has no header row
Use col_names if your file has no header row
write_*()Every read_* has a corresponding write_* function to export data from R.
# Comma delimiter
write_csv(dat, file = "data-clean/your_data.csv")
# Semicolon delimiter
write_csv2(dat, file = "data-clean/your_data.csv")
# tab delimiter
write_tsv(dat, file = "data-clean/your_data.txt")
# Any delimiter, e.g. ";" or "----"
write_delim(dat, file = "data-clean/your_data.csv", delim = ";")
write_delim(dat, file = "data-clean/your_data.txt", delim = "----")The readxl package is part of the tidyverse, but you need to load it explicitly
By default, this reads the first sheet. You can read other sheets with:
read_excel also has other functionality, like skipping rows etc.?read_excel and the package documentation for more functionalityA little warning:
summary function and checking if the number of rows etc. is correctwrite_excel)read_dta, read_spss, write_dta, write_spss, …)read_sheet, write_sheet)read_*() in a variable (e.g. trees) to work with it latertrees instead of data or my_data)? if in doubt
Task (25 min)
Read and write data files
Find the task description here
.csv, .txt instead of .xlsx)species_name instead of species namejanitor::clean_names() from the janitor package. as a decimal separator (not ,)data-raw/my_data.csv instead of data raw/my data.csvSelina Baldauf // Import and export data