-
Joined
Sep 26, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method 1: case_when() | |
umaru = umaru %>% mutate(depression = case_when(BECK < 10 ~ 1, | |
BECK < 19 ~ 2, | |
BECK < 30 ~ 3, | |
BECK >= 30 ~ 4)) | |
Method 2: Avec case_when() + between() (lisible) | |
library(dplyr) | |
umaru <- umaru %>% | |
mutate( | |
depression = case_when( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Delete a variable | |
M2SGS_disc <- M2SGS %>% select(-DISTANCE_BDX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tbl_summary(M2SGS, include = c("SEXE", "M1_SP", "DISTANCE_BDX"), statistic = list( all_continuous() ~ "{mean} ({sd})" ), digits = ( all_continuous() ~ c(1, 1) ) ) | |
# Explication: | |
## statistic = list(all_continuous() ~ "{mean} ({sd})") | |
### Normally, continuous variables are summarized with median (IQR) by default. Here, you override that: For all continuous variables, display: mean (standard deviation) | |
### The "{}" are placeholders — {mean} is replaced by the mean, {sd} by the standard deviation. | |
## d) digits = (all_continuous() ~ c(1, 1)) | |
### Controls number formatting (number of decimal places). For all continuous variables, both the mean and standard deviation will be shown with 1 decimal place. | |
### Example: 45.3 (12.7) instead of 45.34567 (12.7345). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hist(M2SGS$DISTANCE_BDX, xlab = "Distance à Bordeaux", ylab = "nombre d'étudiants", main = "Distribution de la distance entre Bordeaux et le lieu de naissance des étudiants du M2 SGS-SM - représentation par un histogramme", col = "cadetblue") | |
#rajouter des titres à l’axe des abscisses (xlab), | |
#rajouter des titres à l’axe des ordonnées (ylab), | |
#réduire la taille du titre (cex.main), | |
#avoir des données plus précises en réduisant les intervalles (breaks qui permet de faire varier le nombre de classes présentées : + il y a de classes, + c’est précis) | |
#avoir un axe des abscisses plus ou moins précis (xaxp), | |
#avoir les fréquences au lieu des effectifs (probability = TRUE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load the package | |
library(lubridate) | |
# Choose the right parser | |
ymd("2025-09-25") # works for "YYYY-MM-DD" | |
dmy("25/09/2025") # works for "DD/MM/YYYY" | |
mdy("09-25-2025") # works for "MM-DD-YYYY" | |
# Apply to the dataset | |
M2SGS$Date <- dmy(M2SGS$Date) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
M2SGS <- read.csv2(file = "Liste_M2SGS_2025.csv", header = TRUE, sep = ";", dec = ",") | |
# read.csv2 : c’est une fonction qui sert à importer un fichier CSV dans R. La version csv2 est utilisée pour les fichiers au format européen, où : | |
##le séparateur de colonnes est ; (point-virgule), et le séparateur décimal est , (virgule). | |
## (Contrairement à read.csv qui utilise , comme séparateur de colonnes et . comme séparateur décimal.) | |
## header = TRUE : cela indique que la première ligne du fichier contient les noms des colonnes (pas des données). | |
## sep = ";" : précise que le séparateur de colonnes est le point-virgule ;. (Par défaut, c’est déjà le cas avec read.csv2, donc c’est redondant mais clair.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#1. Check Current Working Directory | |
getwd() | |
########################### | |
#2. Set Working Directory | |
setwd("C:/Users/YourName/Documents/Project") | |
############################ | |
#3. Use RStudio Menu | |
## Session → Set Working Directory → Choose Directory… | |
############################ | |
#4. Use here Package (Project-Oriented) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(installr) | |
updateR() |