This repository contains the materials for D-Lab's R Fundamentals workshop. No prior experience with R required.
In this workshop, we provide a broad overview of the fundamentals to using R, a programming language geared toward statistical analysis and data science.
The workshop is divided into four parts, which cover the following topics:
- Part 1: Introduction to R, navigating RStudio, variable assignment, data types and coercion, and data structures.
- Part 2: Working with data frames: importing, subsetting, filtering, and merging.
- Part 3: Data visualization using R and
ggplot2
. - Part 4: Functions, for loops, and if-else statements.
Prior experience with R is not required.
We will use RStudio to go through the workshop materials, which requires installation of both the R language and the RStudio software. Complete the following steps:
- Download R: Follow the links according to the operating system that you are running. Download the package, and install R onto your compute. You should install the most recent version (at least version 4.0).
- Download RStudio: Install RStudio Desktop. This should be free. Do this after you have already installed R.
- Download these workshop materials:
- Click the green "Code" button in the top right of the repository information.
- Click "Download Zip".
- Extract this file to a folder on your computer where you can easily access it (we recommend Desktop).
- Optional: if you're familiar with
git
, you can instead clone this repository by opening a terminal and enteringgit clone git@github.com:dlab-berkeley/R-Fundamentals.git
.
Now that you have all the required software and materials, you need to run the code:
-
Launch the RStudio software.
-
Use the file navigator to find the
R-Fundamentals
folder that you downloaded from Github. -
Open up the file corresponding to the part of the workshop you're attending (
Part1.R
,Part2.R
,Part3.R
,Part4.R
). -
Place your cursor on a given line and press "Command + Enter" (Mac) or "Control + Enter" (PC) to run an individual line of code.
-
The
solutions
folder contains the solutions to the challenge problems.
If you do not have R installed and the materials loaded on your workshop by the time it starts, we strongly recommend using the UC Berkeley Datahub to run the materials for these lessons. You can access the DataHub by clicking this link.
The DataHub downloads this repository, along with any necessary packages, and allows you to run the materials in an RStudio instance on UC Berkeley's servers. No installation is necessary from your end - you only need an internet browser and a CalNet ID to log in. By using the DataHub, you can save your work and come back to it at any time. When you want to return to your saved work, just go straight to DataHub, sign in, and you click on the R-Fundamentals
folder.
If you don't have a Berkeley CalNet ID, you can still run these lessons in the cloud, by clicking this button:
By using this button, however, you cannot save your work.
Check out the following online resources to learn more about R:
- Software Carpentry
- Quick-R
- UCLA idre
- R-bloggers
- R Markdown: The Definitive Guide
- The tidyverse style guide
- Quick Intro to Parallel Computing in R
as well as the following books:
- Bookdown Featured Books
- Kearns GJ. 2010. Introduction to Probability and Statistics in R
- Wickham H. 2014. Advanced R
- R for Data Science
- Lander J. 2013. R for everyone: Advanced analytics and graphics
- Matloff N. 2011. The art of R programming: A tour of statistical software design
- Brunsdon C, Comber L. 2015. An Introduction to R for Spatial Analysis and Mapping
- James G, Witten D, Hastie T, Tibshirani R. 2013. An Introduction to Statistical Learning: With Applications in R, 7th edition
D-Lab works with Berkeley faculty, research staff, and students to advance data-intensive social science and humanities research. Our goal at D-Lab is to provide practical training, staff support, resources, and space to enable you to use R for your own research applications. Our services cater to all skill levels and no programming, statistical, or computer science backgrounds are necessary. We offer these services in the form of workshops such as R Fundamentals, one-to-one consulting, and working groups that cover a variety of research topics, digital tools, and programming languages.
Visit the D-Lab homepage to learn more about us. View our calendar for upcoming events, and also learn about how to utilize our consulting and data services.
Here are other R workshops offered by the D-Lab:
- Fast-R
- R Data Wrangling
- R Graphics with ggplot2
- R Functional Programming
- Project Management in R
- Geospatial Fundamentals in R with sf
- Census Data in R
- Advanced Data Wrangling in R
- Introduction to Machine Learning in R
- Unsupervised Learning in R
- R Machine Learning with tidymodels
- Introduction to Deep Learning in R
- Fairness and Bias in Machine Learning
- R Package Development
- Evan Muzzall
- Aniket Kesari
- Jae Yeon Kim
- Sam Abdel-Ghaffar
- Guadalupe Tuñón
- Shinhye Choi
- Patty Frontiera
- Rochelle Terman
- Dillon Niederhut
- Pratik Sachdeva