Nettoyer des données avec R
Maggie Matsui
Content Developer @ DataCamp
| Donnée | Exemples de valeurs |
|---|---|
| Statut marital | unmarried, married |
| Catégorie de revenu du foyer | 0-20K, 20-40K, ... |
| Taille de T-shirt | S, M, L, XL |
factor, chaque catégorie est stockée comme un nombre et possède une étiquette correspondante| Donnée | Étiquettes | Représentation numérique |
|---|---|---|
| Statut marital | unmarried, married |
1, 2 |
| Catégorie de revenu du foyer | 0-20K, 20-40K, ... |
1, 2, ... |
| Taille de T-shirt | S, M, L, XL |
1, 2, 3, 4 |
tshirt_size
L XL XL L M M M L XL L S M M S S M XL S L S ...
Levels: S M L XL
levels(tshirt_size)
"S" "M" "L" "XL"
factors ne peuvent pas contenir de valeurs en dehors de celles prédéfinies| Donnée | Modalités | Non autorisé |
|---|---|---|
| Statut marital | unmarried, married |
divorced |
| Catégorie de revenu du foyer | 0-20K, 20-40K, ... |
10-30K |
| Taille de T-shirt | S, M, L, XL |
S/M |



study_data
name birthday blood_type
1 Beth 2019-10-20 B-
2 Ignatius 2020-07-08 A-
3 Paul 2019-08-12 O+
4 Helen 2019-03-17 O-
5 Jennifer 2019-12-17 Z+
6 Kennedy 2020-04-27 A+
7 Keith 2019-04-19 AB+
blood_types
blood_type
1 O-
2 O+
3 A-
4 A+
5 B+
6 B-
7 AB+
8 AB-
study_data
name birthday blood_type
1 Beth 2019-10-20 B-
2 Ignatius 2020-07-08 A-
3 Paul 2019-08-12 O+
4 Helen 2019-03-17 O-
5 Jennifer 2019-12-17 Z+ <--
6 Kennedy 2020-04-27 A+
7 Keith 2019-04-19 AB+
blood_types
blood_type
1 O-
2 O+
3 A-
4 A+
5 B+
6 B-
7 AB+
8 AB-

study_data %>%
anti_join(blood_types, by = "blood_type")
name birthday blood_type
1 Jennifer 2019-12-17 Z+

study_data %>%
semi_join(blood_types, by = "blood_type")
name birthday blood_type
1 Beth 2019-10-20 B-
2 Ignatius 2020-07-08 A-
3 Paul 2019-08-12 O+
4 Helen 2019-03-17 O-
5 Kennedy 2020-04-27 A+
6 Keith 2019-04-19 AB+
Nettoyer des données avec R