Laboratory of Statistics and Mathematics 2025/2026
Basic math:
R Functions: always called by name_of_the_function()
Logical values: represent a TRUE/FALSE
statement
[1] TRUE
Factors: categorical variables with known levels
Lists:
List of objects of potentially different nature
Connect to https://giuseppealfonzetti.github.io/LSM/
Click on the “Material” (💻) icon corresponding to today lab.
Download the Excel file.
Rstudio
and create an R Project
for today’s practice within that folder..xlsx
file in your project directory in a subdirectory called data
.R Script
file. Here you will write your R commands.here
package to manage file paths.library()
commands needed to perform the analysis. Today we will useAfter loading the R packages, use the i_am()
function from the here
package to tell R where your script is located. If your script is called my_script.R
, run
Now that R knows your position in the directory tree of your laptop, we can read the xlsx
file stored in the data
folder with
# A tibble: 4 × 6
last_name first_name department seniority salary ID
<chr> <chr> <chr> <dbl> <dbl> <dbl>
1 al-Harron Fikra Marketing 4 72654. 1001
2 Whitaker Jalen HR 15 164507. 1002
3 Pillow Cleevens Sales 7 102665. 1003
4 Holguin Austin I.T. 9 138793. 1004
Visualise all employees in the Marketing department:
# A tibble: 22 × 6
last_name first_name department seniority salary ID
<chr> <chr> <chr> <dbl> <dbl> <dbl>
1 al-Harron Fikra Marketing 4 72654. 1001
2 Martinez Yessica Marketing 9 108185. 1023
3 Green Sarye Marketing 15 154446. 1029
4 Wall Kayla Marketing 4 79165. 1063
5 Wynter Michael Marketing 2 64957. 1065
6 Briseno Dominick Marketing 15 154728. 1073
7 Hennefeld Mitchell Marketing 6 85930. 1074
8 Mccarthy Angelica Marketing 12 137013. 1080
9 Diltz Zachary Marketing 4 75023. 1087
10 Magor Jacob Marketing 15 156230. 1093
# ℹ 12 more rows
Sort employees by increasing seniority
# A tibble: 150 × 6
last_name first_name department seniority salary ID
<chr> <chr> <chr> <dbl> <dbl> <dbl>
1 al-Momin Mu'mina Sales 0 47359. 1009
2 Heng Marina Accounting 0 42770. 1026
3 Huynh Alicia Finance 0 61532. 1027
4 Zavala Kristina Finance 0 61431. 1068
5 el-Ameen Haneef Finance 0 58284. 1089
6 al-Abdallah Labeeb Finance 0 59477. 1106
7 Hiler Margaret Finance 0 60065. 1123
8 Zheng Brittany I.T. 0 52634. 1126
9 al-Jamal Muna Marketing 0 42664. 1128
10 Apodaca-Anaya Daniel Marketing 0 43220. 1148
# ℹ 140 more rows
Select employees in the Marketing department AND sort them by increasing seniority:
# A tibble: 22 × 6
last_name first_name department seniority salary ID
<chr> <chr> <chr> <dbl> <dbl> <dbl>
1 al-Jamal Muna Marketing 0 42664. 1128
2 Apodaca-Anaya Daniel Marketing 0 43220. 1148
3 Wynter Michael Marketing 2 64957. 1065
4 al-Harron Fikra Marketing 4 72654. 1001
5 Wall Kayla Marketing 4 79165. 1063
6 Diltz Zachary Marketing 4 75023. 1087
7 Tuccy Samantha Marketing 5 81015. 1110
8 Hennefeld Mitchell Marketing 6 85930. 1074
9 Gonzalez-Bolivar Luis Marketing 6 87191. 1108
10 Raibon Taneja Marketing 6 87482. 1111
# ℹ 12 more rows
# A tibble: 6 × 2
department total_salary
<chr> <dbl>
1 Accounting 1856399.
2 Finance 3004418.
3 HR 2142249.
4 I.T. 3120520.
5 Marketing 2394822.
6 Sales 3049907.
# A tibble: 6 × 4
department total_salary average_salary n_employees
<chr> <dbl> <dbl> <int>
1 Accounting 1856399. 80713. 23
2 Finance 3004418. 93888. 32
3 HR 2142249. 107112. 20
4 I.T. 3120520. 124821. 25
5 Marketing 2394822. 108856. 22
6 Sales 3049907. 108925. 28
Let’s say we want to export a summary table of the data and the scatterplot for salary and seniority:
Course Introduction