Introduction to R
On this page:
Course description
Target audience
Course objectives
Prerequisites
Course content
Preparation for the course
References
Instructor’s Biography
Duration: 8 hours/2 days
|
February 15 |
11:00-16:00 |
|
February 16 |
11:00-16:00 |
An hour-long lunch break from 13:00-14:00 with RECSM Winter School participants and members
Format
In-person only
Lecturer
Dr. Toni Rodon
Course Description
R is a free, open-source programming language for statistical analysis and data visualization. It has become one of the standard tools for quantitative research in the social sciences and many other disciplines. Thousands of user-written packages, full control over graphics and a large, active community make it useful at every stage of a research project, from importing and cleaning raw data to analyzing it and presenting the results.
This course is a practical introduction to R. Over two days, participants will learn the building blocks of the language and, just as importantly, how to read and understand R code written by others. The first day covers R objects, reading and writing data, data types, cleaning and merging datasets, and how to get help when code doesn’t work. The second day moves on to data visualization, mapping, basic statistical analysis and how to communicate results.
The course is mostly hands-on. Each session pairs short explanations with exercises on real data, such as survey and country-level datasets, which participants work through on their own laptops. Participants are encouraged to bring their own research questions or data. Part of the course is set aside to discuss these as a group and to start applying what they have learned to their own projects. The pace adapts to the group, and questions are welcome at any point.
By the end of the course, participants will be able to run a simple data analysis in R from start to finish and will have a solid base for learning more on their own. The course also works as a refresher for anyone planning to take other RECSM courses taught in R.
Target Audience
The course is for anyone who wants to start working with data in R. No previous programming experience is needed. It suits researchers and students in the social sciences, including political science, sociology, economics, communication, psychology, public policy and demography. It is just as useful for people in the humanities, health sciences and other fields that increasingly work with quantitative data.
It is open to participants at any career stage. Master’s and PhD students will find it useful when they are about to start empirical work, and postdocs and more senior researchers can use it to move from other software such as Stata, SPSS or Excel to R. It is also relevant outside academia, for professionals in public administration, think tanks, NGOs, polling and market research firms, and data journalism who need to handle, analyze and visualize data.
The course will also suit participants who have used R before but feel unsure about the basics, and those who want a refresher before taking other RECSM courses taught in R.
Course objectives
The course aims to give participants the foundations they need to work independently with data in R. It focuses on two core goals: understanding the building blocks of the R language, and learning to read and understand R code written by others, so that participants can adapt existing code to their own research.
By the end of the course, participants will be familiar with the following:
-
The R environment and its two main development environments, RStudio and Positron, plus how to organize a project and write reproducible scripts.
-
The R and RStudio environment, and how to organize a project and write reproducible scripts.
-
The main types of R objects (vectors, data frames, lists) and data types (numeric, character, factor, logical).
-
Importing data from common formats and exporting results.
-
Cleaning, recoding and transforming variables, and merging datasets.
-
Finding help and solving errors with documentation, error messages and online resources.
-
Producing clear, publication-quality graphs and simple maps.
-
Running basic statistical analyses, such as descriptive statistics, cross-tabulations and regression models.
-
Presenting and communicating results in tables and figures.
-
Applying these tools to their own research questions and data.
Prerequisites
This course has no formal prerequisites. No previous experience with R or any other programming language is needed.
Some background will help participants get more out of the course, but it is not required:
-
Basic familiarity with introductory statistics, such as means, distributions, correlation and the basic idea of regression. The course shows how to run these analyses in R but does not teach the statistics behind them.
-
Some experience handling data in a spreadsheet such as Excel or in other statistical software such as Stata or SPSS will be helpful.
-
Basic computer skills, such as installing software and managing files and folders on their own laptop.
Course Content
|
Day |
Time |
Course Content |
|
Day 1 |
10h00- 11h00 | Welcome coffee with RECSM faculty, Winter School professors, and students |
|
11h00- 13h00 |
|
|
|
13h00- 14h00 |
Lunch |
|
|
14h00- 16h00 |
|
|
|
16h00- 17h00 |
Open office hours (optional): Help with installation issues, the day’s exercises or participants’ own data |
|
|
|
||
|
Day 2 |
11h00- 13h00 |
|
|
13h00- 14h00 |
Lunch |
|
|
14h00- 16h00 |
|
|
|
16h00- 17h00 |
Open office hours (optional): time to work on participants’ own projects with the instructor’s support |
|
| 17h00-18h00 | Keynote by the RECSM director on going beyond conventional surveys | |
Preparation for the course
No preparation is needed. Participants should bring their own laptop (Windows, macOS or Linux) with ideally the following software installed before the first session:
-
R (latest version), free from CRAN: https://cran.r-project.org/
-
An editor to work with R, either of these two (both are free):
-
RStudio Desktop: https://posit.co/download/rstudio-desktop/
-
Positron: https://positron.posit.co/download.html
-
Any other editor you wish.
-
Install R first, then the editor. All the software is free and open source, so no licenses are needed. Any packages and datasets used in the course will be installed and provided during the sessions.
Participants using a laptop managed by their institution should check that they have permission to install software. If anyone has trouble installing, the instructor can help during the first session or the office hours.
References
Participants don’t need to read anything before the course. The references below are optional, for consolidating and extending what is covered in class. Several are free to read online.
General introductions to R
-
Wickham, Hadley, Mine Çetinkaya-Rundel, and Garrett Grolemund. 2023. R for Data Science. 2nd ed. Sebastopol, CA: O’Reilly. Free online: https://r4ds.hadley.nz/
-
Llaudet, Elena, and Kosuke Imai. 2022. Data Analysis for Social Science: A Friendly and Practical Introduction. Princeton, NJ: Princeton University Press.
-
Monogan III, James E. 2015. Political Analysis Using R. Cham: Springer.
-
Dalgaard, Peter. 2008. Introductory Statistics with R. 2nd ed. New York: Springer.
-
Imai, Kosuke, and Nora Webb Williams. 2022. Quantitative Social Science: An Introduction in tidyverse. Princeton, NJ: Princeton University Press.
Data visualization and mapping
-
Healy, Kieran. 2019. Data Visualization: A Practical Introduction. Princeton, NJ: Princeton University Press. Free online: https://socviz.co/
-
Lovelace, Robin, Jakub Nowosad, and Jannes Muenchow. 2025. Geocomputation with R. 2nd ed. Boca Raton, FL: CRC Press. Free online: https://r.geocompx.org/
Instructor’s Biography
Toni Rodon is an Associate Professor of Political Science in the Department of Political and Social Sciences at Universitat Pompeu Fabra (UPF), where he is also Delegate for Knowledge Transfer in the Social Sciences and Humanities. He was a postdoctoral researcher at Stanford University (2014–2016) and at the London School of Economics and Political Science (2017–2019).
His research focuses on political and electoral behaviour, especially electoral participation, as well as political geography, comparative politics, historical political economy, public opinion and nationalism. His work draws on large electoral, historical and survey datasets. He leads the VEARLYDEM project, which includes the Electoral Atlas of the Spanish Second Republic, and is a co-author of the ATTCLIMATE dataset on public attitudes towards climate change. www.tonirodon.cat