[1] 9
14/10/2026
Important
Before completing this session, please carefully read about the prerequisites.
| Prerequisite | Description | Where to find it |
|---|---|---|
| R and RStudio installed | Latest versions of both R and RStudio | Download RStudio |
| Accessibility sheet for computers | Fundamentals of computer literacy | Download |
What is your level of familiarity with R and RStudio?
I have never heard of it before
I have heard of it but have never worked with it
I have basic understanding and experience with it
I am very familiar and have worked with it extensively
On a scale of 1–5, how intimidated do you feel by programming or coding (e.g., R/RStudio)?
(1 = Not intimidated at all, 5 = Very intimidated)
1
2
3
4
5
Have you used any programming language (R, Python, JavaScript, C) before?
No, never
Yes, a little (e.g., basic commands)
Yes, moderately (e.g., small projects)
Yes, extensively (e.g., on an almost daily basis)
What do we see in the results?
At the end of this session, you will be able to …
You might see some words for the first time or some familiar words used in a different way. What do you associate with the terms below?
#) that R ignores. You can use this function to explain what the code does or make notes throughout your work.+, -, *, <, or ==) that tells R to perform a specific action.R (https://www.r-project.org/) is an free and open source programming language
Why R?

Open RStudio and check if you can see everything that’s on the slide.
(You might only see three panes on your screen)
| Symbol | Operation |
|---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
^ |
Exponentiation |
sqrt() |
Square Root |
log() |
(Natural) Logarithm |
Using the table on the previous slide, run the following math operations directly in the Console of RStudio.
Let’s use the Console!
You can run code from the Console by typing in the Console and then pressing Enter on your keyboard.
An R script is a text file containing your R commands.
It is an easy way to save and share code
You can run code from an R script by:
You can also add comments or notes to your code by using #

Step 1: On your device

Step 2: In RStudio
File → then click Save As...SaveWith R, you can also:
Check if two numbers are equal or unequal
Check if a number is larger or smaller than another number
R returns a logical value:
TRUE or FALSE| Symbol | Operation |
|---|---|
== |
Equals |
!= |
Not Equal |
> and < |
Greater and Lesser Than |
>= and <= |
Greater Than or Equal / Less Than or Equal |
& |
logical AND |
| |
logical OR |
! |
logical NOT |
TRUE or FALSE?
Data types define what kind of values you are working with

Can R perform the same operation on different data types?
Everything in R is an object, and oftentimes, we want to work with an object repeatedly.
<-The assignment arrow points to the object
Take note of the order: we put the variable or object name first, then the assignment arrow <-, and lastly the number or value. The arrow should be pointing the object- it would not work if you put 1 <- x
The object then appears in the Environment pane (top right pane).
Try following the example and create your objects!
Okay, I made objects… what now?
Let’s use the objects in a new operation:
Object reassignment
When you reuse an object name and assign it a new value, R overwrites the previous value.
f(x) = 2 * x, then inputting x = 3 returns 6.(), such as sum().c() functionc() function to manipulate multiple items at once.[1] 60
food
Burger Pasta Pizza
1 2 1
R comes with many built-in numeric functions:
| Function | What it does | |
|---|---|---|
sum() |
Adds all values together | |
mean() |
Calculates the arithmetic mean (average) | |
sd() |
Calculates the standard deviation | |
exp() |
Calculates the exponential function (\(e^x\)) | |
round() |
Rounds a number |
R also comes with many built-in character functions:
| Function | What it does |
|---|---|
sort() |
Sort values in alphabetical order |
unique() |
Shows the unique values in the set |
table() |
Counts the values in a table |
toupper() |
Transforms all the letters to uppercase |
tolower() |
Transforms all the letters to lowercase |
Most functions take multiple arguments (inputs).
function_name(argument1 = x, argument2 = y)Do all functions need multiple arguments?
No, not all functions need multiple arguments, but for some, it is required.
Example: The round() function
Naming your arguments makes your code easier to read!
If you name the arguments (using the names “x” and “digits”), the order does not matter: round(digits = 2, x = 3.14159) works identically.
Ignoring the digits argument
If you are curious, try running the round() function without specifying the digits = argument. What happens? Why might that be?
What does the # symbol do in R?
What happens when you “run” code in R?
What will R return for this comparison?
49 < 50
Which of the following is a character value in R?
Why does the following produce an error?
4 + "five"
What do we see in the results?
Do I have to memorize all of the functions and arguments?
There are two main ways to look up a function.
Method 1: Using the Console
? into the console immediately followed by the function name and press Enter.Method 2: Using the Help Tab

Help pages can look intimidating, but you only need to focus on a few key sections:
Example: For the sort() function we can see that it can also use character vectors or values as input and orders them.

Is reverse alphabetical order increasing or decreasing?
Reverse alphabetical order means arranging items from Z to A. This means that the order is decreasing.
Collections of values are called data
R provides ways to store data in different data structures:
What does a vector do? Stores multiple values in an object.
Example:
Vectors and data type
What do you notice about the values in the vector stored in scores? All values in a vector should be of the same data type.
Character data type
Reminder: character data types need to be wrapped in quotation marks " ".
What does a list do? Stores different types of data together.
Example for a list:
What does a dataframe do? Stores data in rows and columns.
| Name | Age | Food |
|---|---|---|
| Tim | 19 | Pizza |
| Tom | 20 | Pizza |
| Anna | 21 | Pasta |
Look familiar?
Think of a dataframe like a spreadsheet. The top row is the heading and the information below (within each column) is the observation corresponding to the heading.
Create a dataframe with the data.frame() function
What does indexing do? Allows us to access specific parts of our data, such as:
Each element in a vector has a position.
| Position | 1 | 2 | 3 |
|---|---|---|---|
| Value | 19 | 20 | 21 |
Selecting individual values
[ ] to call on a value by its positionSelecting multiple values
You can retrieve more than one value at once.
You can also select a range:
Accessing rows and columns in a dataframe
You can call on values directly from the row and column of data frames.
To use indexing, use [ ] and follow this general format:
dataframe[row,column]Calling values by using just numbers can get confusing.
Luckily, there is a way to call on the values by column name using the $ operator: dataframe$column_name
$ and []Look at the following example to see how $ and [ ] can be used together:
What does this do?
$ selects the food column in the people_data data frame[] gives you the third valueUse $ and [] accordingly to retrieve the following information from the the people_data data frame:
Can you identify some practical benefits of using R/RStudio?
What obstacles do you anticipate in using it consistently?
How can R/RStudio support you in your upcoming projects?
Create a short R script that builds on what was covered today
sum(), mean(), length(), sort(), or table().[].Self-Assessment
Use this assignment to assess your learning of, and progress with, R/RStudio; reflect on any challenges you faced and how you overcame them.
Where are we at?
On a scale of 1–5, how intimidated do you feel by programming or coding (e.g., R/RStudio) after completing this session? (1 = Not intimidated at all, 5 = Very intimidated)
How confident do you feel using the RStudio environment after this session?
How comfortable do you feel about using R and RStudio for mathematical operations?
How comfortable do you feel using R objects (e.g., vectors and data frames) to organize and manipulate your research data?
What part of the lesson, if any, still feels confusing or unclear?
4. Was there a practical exercise or example that helped your understanding the most? Why?
What do we see in the results?
See you next time!
Creator: Sanchez Steinhagen, Caterina Luz (
0009-0006-4783-1110)
Creator: Sharma, Tejaswini (
0000-0000-0000-0000)
Creator: Waterfield, Elizabeth (
0009-0006-3725-6730)
Creator: Rieger, David (
0009-0004-3701-3101)
Reviewer: Von Grebmer zu Wolfsthurn, Sarah (
0000-0002-6413-3895)
Reviewer: Middleton, Sara Lil (
0000-0002-6413-3895)
This work was originally created by Nicklas Hafiz. His work was subsequently adapted by Caterina Luz Sanchez Steinhagen, Tejaswini Sharma, David Rieger, Elizabeth Waterfield, Sara Lil Middleton and Sarah von Grebmer zu Wolfsthurn. The current work is licensed under a Creative Commons Attribution 4.0 SA International License (CC-BY-SA 4.0). Code snippets are dedicated to the public domain and are licensed under a Creative Commons Universal Licence (CC0 1.0).
Please cite these materials as: Sanchez-Steinhagen, C. L., Sharma, T., Rieger, D., Waterfield, E., Middleton, S., & Von Grebmer zu Wolfsthurn, S. (2026). Introduction to R: Part I [Quarto slides]. LMU Open Science Center. https://lmu-osc.github.io/teaching-material-for-novices/open-research-tools/r-part-I

LMU Open Science Center