Reputation: 697
I have two data sets, related to each other through an index column. One data set contains data about individuals, while the other data set contains data about households of those individuals. The index column is a unique number given to a household. I am especially interested in married women and and their living conditions, and I would like to create a data set for married women only, that would contain the following information for each woman:
I would like someone to help me write a dplyr
script to create this data frame. Thank you very much in advance.
PS: here is an overview of both data sets:
> str(household)
tibble [15,970 × 792] (S3: tbl_df/tbl/data.frame)
$ N_ménage : num [1:15970] 1 2 3 4 5 6 7 8 9 10 ...
..- attr(*, "label")= chr "Numéro du ménage"
..- attr(*, "format.spss")= chr "F5.0"
$ coef_ménage : num [1:15970] 165 165 165 165 165 165 165 165 165 165 ...
..- attr(*, "label")= chr "Coefficient d'extrapolation des ménages"
..- attr(*, "format.spss")= chr "F8.0"
..- attr(*, "display_width")= int 9
$ coef_indiv : num [1:15970] 560 676 677 796 789 ...
..- attr(*, "label")= chr "Coefficient d'extrapolation des individues"
..- attr(*, "format.spss")= chr "F8.0"
..- attr(*, "display_width")= int 9
$ Milieu : dbl+lbl [1:15970] 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...
..@ label : chr "MIilieu de résidence"
..@ format.spss : chr "F1.0"
..@ display_width: int 5
..@ labels : Named num [1:2] 1 2
.. ..- attr(*, "names")= chr [1:2] "Urbain" "Rural"
$ Région_12 : dbl+lbl [1:15970] 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,...
..@ label : chr "Régions"
..@ format.spss : chr "F2.0"
..@ display_width: int 11
..@ labels : Named num [1:12] 1 2 3 4 5 6 7 8 9 10 ...
.. ..- attr(*, "names")= chr [1:12] "Tanger-Tétouan-Al Hoceïma" "Oriental" "Fès-Meknès" "Rabat-Salé-Kénitra" ...
$ Taille_ménage : chr [1:15970] " 2" " 3" " 3" " 3" ...
..- attr(*, "format.spss")= chr "A2"
$ Taille_agregée : dbl+lbl [1:15970] 2, 3, 3, 3, 4, 5, 4, 6, 6, 6, 2, 3, 3, 3, 4, 5, 4, 6, 6, 6, 2, 2, 3, 4, 4, 4, 5, 5,...
..@ label : chr "Taille du ménage"
..@ format.spss : chr "F1.0"
..@ display_width: int 14
..@ labels : Named num [1:6] 1 2 3 4 5 6
.. ..- attr(*, "names")= chr [1:6] "1 personne" "2 personnes" "3 personnes" "4 personnes" ...
$ Pauvre : dbl+lbl [1:15970] 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,...
..@ format.spss: chr "F1.0"
..@ labels : Named num [1:2] 0 1
.. ..- attr(*, "names")= chr [1:2] "Non pauvre" "Pauvre"
$ Vulnérable : dbl+lbl [1:15970] 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,...
..@ format.spss : chr "F1.0"
..@ display_width: int 10
..@ labels : Named num [1:2] 1 2
.. ..- attr(*, "names")= chr [1:2] "Vulnérable" "Non vulnérable"
$ Quintiles : dbl+lbl [1:15970] 5, 4, 4, 5, 5, 5, 5, 5, 1, 5, 5, 3, 5, 5, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5,...
..@ label : chr "Quintiles_National"
..@ format.spss : chr "F1.0"
..@ display_width: int 11
..@ labels : Named num [1:5] 1 2 3 4 5
.. ..- attr(*, "names")= chr [1:5] "<= 7149,77" "7149,78 - 9964,29" "9964,30 - 13639,80" "13639,81 - 20394,92" ...
$ Deciles : dbl+lbl [1:15970] 10, 7, 8, 10, 10, 9, 10, 10, 2, 9, 10, 6, 9, 10, 10, 9, 10, 10, 3, 9, 10,...
..@ label : chr "Déciles_National"
..@ format.spss : chr "F1.0"
..@ display_width: int 10
..@ labels : Named num [1:10] 1 2 3 4 5 6 7 8 9 10
.. ..- attr(*, "names")= chr [1:10] "<= 5522,56" "5522,57 - 7149,77" "7149,78 - 8529,14" "8529,15 - 9964,29" ...
$ Quintileurbain : dbl+lbl [1:15970] 5, 3, 4, 5, 5, 5, 5, 5, 1, 4, 5, 3, 4, 5, 5, 4, 5, 5, 1, 4, 5, 5, 5, 5, 5, 5, 5, 4,...
..@ label : chr "Quintiles_urbain"
..@ format.spss : chr "F1.0"
..@ display_width: int 5
..@ labels : Named num [1:5] 1 2 3 4 5
.. ..- attr(*, "names")= chr [1:5] "<= 8932,27" "8932,28 - 12240,48" "12240,49 - 16693,25" "16693,26 - 25063,80" ...
$ Decileurbain : dbl+lbl [1:15970] 10, 6, 8, 10, 10, 9, 10, 10, 2, 8, 10, 5, 8, 10, 10, 8, 10, 10, 2, 8, 9,...
..@ label : chr "Deciles_urbain"
..@ format.spss : chr "F2.0"
..@ display_width: int 5
..@ labels : Named num [1:10] 1 2 3 4 5 6 7 8 9 10
.. ..- attr(*, "names")= chr [1:10] "<= 7072,83" "7072,84 - 8932,27" "8932,28 - 10556,50" "10556,51 - 12240,48" ...
$ Quintilerural : dbl+lbl [1:15970] NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,...
..@ label : chr "Quintiles_rural"
..@ format.spss : chr "F1.0"
..@ display_width: int 5
..@ labels : Named num [1:5] 1 2 3 4 5
.. ..- attr(*, "names")= chr [1:5] "<= 5590,11" "5590,12 - 7660,28" "7660,29 - 9909,80" "9909,81 - 13779,63" ...
$ Decilerural : dbl+lbl [1:15970] NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,...
..@ label : chr "Déciles_ rural"
..@ format.spss : chr "F2.0"
..@ display_width: int 5
..@ labels : Named num [1:10] 1 2 3 4 5 6 7 8 9 10
.. ..- attr(*, "names")= chr [1:10] "<= 4376,60" "4376,61 - 5590,11" "5590,12 - 6606,89" "6606,90 - 7660,28" ...
$ Sexe_CM : dbl+lbl [1:15970] 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1,...
..@ label : chr "Sexe du CM"
..@ format.spss : chr "F1.0"
..@ display_width: int 3
..@ labels : Named num [1:2] 1 2
.. ..- attr(*, "names")= chr [1:2] "Masculin" "Féminin"
$ Age_CM : chr [1:15970] "26" "36" "38" "34" ...
..- attr(*, "label")= chr "Age"
..- attr(*, "format.spss")= chr "A2"
..- attr(*, "display_width")= int 3
$ Age_quin_CM : dbl+lbl [1:15970] 6, 8, 8, 7, 9, 7, 9, 11, 10, 11, 6, 8, 8, 7, 9, 7, 9, 11, 10, 11, 14,...
..@ label : chr "Age quinquenal du chef de ménage"
..@ format.spss : chr "F2.0"
..@ display_width: int 10
..@ labels : Named num [1:16] 1 2 3 4 5 6 7 8 9 10 ...
.. ..- attr(*, "names")= chr [1:16] "0-4" "5-9" "10-14" "15-19" ...
$ Lieunaissance_CM : num [1:15970] 1 1 2 1 2 1 1 2 2 2 ...
..- attr(*, "label")= chr "Lieu de naissance"
..- attr(*, "format.spss")= chr "F1.0"
..- attr(*, "display_width")= int 3
$ Etat_matrimonial_CM : dbl+lbl [1:15970] 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 4, 2, 2,...
..@ label : chr "Etat matrimoniale du CM"
..@ format.spss : chr "F1.0"
..@ display_width: int 3
..@ labels : Named num [1:4] 1 2 3 4
.. ..- attr(*, "names")= chr [1:4] "Célibataire" "Marié" "Divorcé" "Veuf"
$ Niveau_scolaire_agreg_CM : dbl+lbl [1:15970] 2, 4, 2, 5, 5, 4, 3, 4, 4, 0, 2, 4, 2, 5, 5, 4, 3, 4, 4, 0, 3, 0, 4, 4, 6, 4, 4, 4,...
..@ label : chr "Plus haut niveau scolaire"
..@ format.spss : chr "F1.0"
..@ display_width: int 21
..@ labels : Named num [1:7] 0 1 2 3 4 5 6
.. ..- attr(*, "names")= chr [1:7] "Sans niveau" "Préscolaire" "Primaire" "Secondaire collégial" ...
$ Diplôme_agregé_CM : dbl+lbl [1:15970] 2, 2, 1, 3, 3, 2, 2, 2, 2, 1, 2, 2, 1, 3, 3, 2, 2, 2, 2, 1, 2, 1, 3, 2, 1, 3, 3, 3,...
..@ label : chr "Le plus haut Diplôme"
..@ format.spss : chr "F1.0"
..@ display_width: int 10
..@ labels : Named num [1:3] 1 2 3
.. ..- attr(*, "names")= chr [1:3] "Sans diplôme" "Niveau moyen" "Niveau supérieur"
$ Type_activité_dominante_CM : dbl+lbl [1:15970] 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 8, 1, 1, 1, 1, 1, 1,...
..@ label : chr "Type d'activité habituelle durant les 12 dérniers mois"
..@ format.spss : chr "F2.0"
..@ display_width: int 15
..@ labels : Named num [1:12] 1 2 3 4 5 6 7 8 9 10 ...
.. ..- attr(*, "names")= chr [1:12] "Actif occupé" "Chômeur ayant déjà travaillé" "Chômeur n' ayant jamais travaillé" "Femme au foyer" ...
$ Profession_agreg_CM : dbl+lbl [1:15970] 6, 4, 5, 2, 4, 4, 2, 5, 5, 3, 6, 4, 5, 2, 4, 4, 2, 5, 5, 3, NA,...
..@ label : chr "Catégories professionnelles dans l'activité habituelle durant les 12 dérniers mois"
..@ format.spss : chr "F1.0"
..@ display_width: int 16
..@ labels : Named num [1:8] 0 1 2 3 4 5 6 9
.. ..- attr(*, "names")= chr [1:8] "Chômeur n'ayant jamais travaillés" "directeurs et cadres de direction, membres des corps législatifs,cadres supérieurs et membres des professions libérales" "Cadres moyens et employés de bureau" "Commerçants, intermédiaires commerciaux et financiers" ...
$ Secteur_activité_agreg_CM : dbl+lbl [1:15970] 4, 1, 3, 5, 2, 2, 5, 2, 3, 1, 4, 1, 3, 5, 2, 2, 5, 3, 3, 1, NA,...
..@ label : chr "Secteur d'activité habituelle durant les 12 dérniers mois"
..@ format.spss : chr "F1.0"
..@ display_width: int 14
..@ labels : Named num [1:7] 0 1 2 3 4 5 9
.. ..- attr(*, "names")= chr [1:7] "Chômeur n'ayant jamais travaillé" "Agriculture, forêt et pêhe" "Industrie" "Batiment et travaux publics" ...
$ Situation_profession_agreg_CM: dbl+lbl [1:15970] 3, 2, 3, 2, 2, 2, 2, 3, 2, 3, 3, 2, 3, 2, 2, 2, 2, 3, 2, 3, 1, 1, 2, 2, 9, 2, 2, 2,...
..@ label : chr "Situation dans la profession habituelle durant les 12 dérniers mois"
..@ format.spss: chr "F1.0"
..@ labels : Named num [1:7] 0 1 2 3 4 5 9
.. ..- attr(*, "names")= chr [1:7] "Chômeur n'ayant jamais travaillé" "Inactif" "Salarié" "Indépendant" ...
$ DAM : num [1:15970] 78028 47075 60254 157237 288210 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH)"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 11
$ DAM_G1 : num [1:15970] 16340 16596 25243 69508 57982 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en alimentation"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 12
$ DAM_G2 : num [1:15970] 1392 0 726 5600 8560 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en habillement"
..- attr(*, "format.spss")= chr "F8.3"
..- attr(*, "display_width")= int 12
$ DAM_G3 : num [1:15970] 10948 18604 12124 15904 43448 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en habitation et dépenses d'énergie"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 12
$ DAM_G4 : num [1:15970] 8572 2634 3658 5572 16240 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en équipements ménagers"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 12
$ DAM_G5 : num [1:15970] 8448 3568 4338 14784 11456 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en hygiène et soins médicaux"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 12
$ DAM_G6 : num [1:15970] 2815 3448 4945 2988 68840 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en transport et communication"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 12
$ DAM_G7 : num [1:15970] 12204 0 1200 3088 56104 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en loisirs, enseignement et culture"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 12
$ DAM_G8 : num [1:15970] 15778 125 5000 30833 15800 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en autres biens et services"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 12
$ DAM_G9 : num [1:15970] 1530 2100 3020 8960 9780 995 1190 13800 434 1690 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en paiments fiscaux, transferts et remboursement des prêts"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 12
$ DAM_hygiene : num [1:15970] 1668 3508 1588 2412 5516 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en hygiène (G51)"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 13
$ DAM_soins_medicaux : num [1:15970] 6780 60 2750 12372 5940 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en soins médicaux (G52+G53)"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 20
$ DAM_Transport : num [1:15970] 1040 520 1820 0 65840 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en transport (G61+G62)"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 15
$ DAM_Communication : num [1:15970] 1775 2928 3125 2988 3000 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en communication (G63)"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 19
$ DAM_Loisirs : num [1:15970] 12204 0 1200 3088 35906 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en loisirs (G71+G72+G73+G74)"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 13
$ DAM_Enseignement : num [1:15970] 0 0 0 0 20198 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en enseignement (G75+G76)"
..- attr(*, "format.spss")= chr "F8.1"
..- attr(*, "display_width")= int 18
$ DAM_Autres_dépenses : num [1:15970] 17308 2225 8020 39793 25580 ...
..- attr(*, "label")= chr "Dépense annuelle par ménage (en DH) en autres biens et services (G8+G9)"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 22
$ DAM_G01 : num [1:15970] 3172 2418 4160 13910 9438 ...
..- attr(*, "label")= chr "Dépense annuelle du ménage du sous groupe 01 (céréales et produits à base de céréales)"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 13
[list output truncated]
and
> str(individual)
tibble [75,691 × 16] (S3: tbl_df/tbl/data.frame)
$ N_ménage : num [1:75691] 1 1 2 2 2 3 3 3 4 4 ...
..- attr(*, "label")= chr "Numéro du ménage"
..- attr(*, "format.spss")= chr "F8.2"
$ Nordre : num [1:75691] 2 1 3 2 1 3 2 1 3 2 ...
..- attr(*, "label")= chr "Numéro d'ordre de l'individu"
..- attr(*, "format.spss")= chr "F2.0"
..- attr(*, "display_width")= int 4
$ Coef_individu : num [1:75691] 168 392 191 178 307 187 183 307 191 178 ...
..- attr(*, "label")= chr "Coefficient individu"
..- attr(*, "format.spss")= chr "F8.2"
..- attr(*, "display_width")= int 4
$ Milieu : dbl+lbl [1:75691] 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...
..@ label : chr "Milieu de résidence"
..@ format.spss : chr "F1.0"
..@ display_width: int 4
..@ labels : Named num [1:2] 1 2
.. ..- attr(*, "names")= chr [1:2] "Urbain" "Rural"
$ Région_12 : dbl+lbl [1:75691] 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,...
..@ label : chr "Régions"
..@ format.spss : chr "F2.0"
..@ display_width: int 11
..@ labels : Named num [1:12] 1 2 3 4 5 6 7 8 9 10 ...
.. ..- attr(*, "names")= chr [1:12] "Tanger-Tétouan-Al Hoceïma" "Oriental" "Fès-Meknès" "Rabat-Salé-Kénitra" ...
$ Sexe : dbl+lbl [1:75691] 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1,...
..@ label : chr "Sexe"
..@ format.spss : chr "F1.0"
..@ display_width: int 4
..@ labels : Named num [1:2] 1 2
.. ..- attr(*, "names")= chr [1:2] "Masculin" "Féminin"
$ Age : num [1:75691] 17 26 1 31 36 0 27 38 2 30 ...
..- attr(*, "label")= chr "Age"
..- attr(*, "format.spss")= chr "F2.0"
..- attr(*, "display_width")= int 4
$ Age_quin : dbl+lbl [1:75691] 4, 6, 1, 7, 8, 1, 6, 8, 1, 7, 7, 2, 3, 9, 9, 1, 2, 10, 6, 7, 1,...
..@ label : chr "Age quinquenal de l'individu"
..@ format.spss : chr "F8.2"
..@ display_width: int 10
..@ labels : Named num [1:16] 1 2 3 4 5 6 7 8 9 10 ...
.. ..- attr(*, "names")= chr [1:16] "0-4" "5-9" "10-14" "15-19" ...
$ Liendeparenté : dbl+lbl [1:75691] 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 3, 2, 1, 3, 3, 7, 2, 1, 3, 3, 2, 1, 3, 3, 3, 3,...
..@ label : chr "Lien de parenté avec le chef de ménage"
..@ format.spss : chr "F2.0"
..@ display_width: int 4
..@ labels : Named num [1:11] 1 2 3 4 5 6 7 8 9 10 ...
.. ..- attr(*, "names")= chr [1:11] "Chef de ménage" "Epoux (se) du chef de ménage" "Fils (fille) du chef de ménage" "Epouse du fils /Epoux de la fille du chef de ménage" ...
$ Etat_matrimonial : dbl+lbl [1:75691] 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 2, 1, 1, 3, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1,...
..@ label : chr "Etat matrimonial"
..@ format.spss : chr "F1.0"
..@ display_width: int 15
..@ labels : Named num [1:4] 1 2 3 4
.. ..- attr(*, "names")= chr [1:4] "Célibataire" "Marié(e)" "Divorcé(e)" "Veuf(ve)"
$ Niveau_scolaire_agreg : dbl+lbl [1:75691] 2, 2, NA, 3, 4, NA, 2, 2, NA, 5, 5, 2, 2, 5, 5, NA, 2, 2, 4, 4, NA,...
..@ label : chr "Le plus haut niveau scolaire"
..@ format.spss : chr "F8.2"
..@ display_width: int 7
..@ labels : Named num [1:7] 0 1 2 3 4 5 6
.. ..- attr(*, "names")= chr [1:7] "Sans niveau" "Préscolaire" "Primaire" "Secondaire collégial" ...
$ Diplôme_agregé : dbl+lbl [1:75691] 1, 2, 0, 2, 2, 0, 1, 1, 0, 3, 3, 0, 1, 3, 3, 0, 0, 1, 2, 2, 0, 0, 1, 2, 0, 0, 2, 2,...
..@ label : chr "Le plus haut diplôme"
..@ format.spss : chr "F4.0"
..@ display_width: int 10
..@ labels : Named num [1:4] 0 1 2 3
.. ..- attr(*, "names")= chr [1:4] "Age moins de 10 ans" "Sans diplôme" "Niveau moyen" "Niveau supérieur"
$ Type_activité_dominante : dbl+lbl [1:75691] 4, 1, NA, 4, 1, NA, 4, 1, NA, 3, 1, NA, 5, 1, 1, NA, 5, 1, 4, 1, NA,...
..@ label : chr "Type d'activité habituelle durant les 12 dérniers mois"
..@ format.spss : chr "F2.0"
..@ display_width: int 9
..@ labels : Named num [1:12] 1 2 3 4 5 6 7 8 9 10 ...
.. ..- attr(*, "names")= chr [1:12] "Actif occupé" "Chômeur ayant déjà travaillé" "Chômeur n' ayant jamais travaillé" "Femme au foyer" ...
$ Profession_agreg : dbl+lbl [1:75691] NA, 6, NA, NA, 4, NA, NA, 5, NA, 0, 2, NA, NA, 2, 4, NA, NA, 4, NA, 4, NA,...
..@ label : chr "Catégories professionnelles dans l'activité habituelle durant les 12 dérniers mois"
..@ format.spss : chr "F1.0"
..@ display_width: int 16
..@ labels : Named num [1:8] 0 1 2 3 4 5 6 9
.. ..- attr(*, "names")= chr [1:8] "Chômeur n'ayant jamais travaillés" "directeurs et cadres de direction, membres des corps législatifs,cadres supérieurs et membres des professions libérales" "Cadres moyens et employés de bureau" "Commerçants, intermédiaires commerciaux et financiers" ...
$ Secteur_activité_agreg : dbl+lbl [1:75691] NA, 4, NA, NA, 1, NA, NA, 3, NA, 0, 5, NA, NA, 5, 2, NA, NA, 2, NA, 2, NA,...
..@ label : chr "Secteur d'activité habituelle durant les 12 dérniers mois"
..@ format.spss : chr "F1.0"
..@ display_width: int 14
..@ labels : Named num [1:7] 0 1 2 3 4 5 9
.. ..- attr(*, "names")= chr [1:7] "Chômeur n'ayant jamais travaillé" "Agriculture, forêt et pêhe" "Industrie" "Batiment et travaux publics" ...
$ Situation_profession_agreg: dbl+lbl [1:75691] 1, 3, NA, 1, 2, NA, 1, 3, NA, 0, 2, NA, 1, 2, 2, NA, 1, 2, 1, 2, NA,...
..@ label : chr "Situation dans la profession habituelle durant les 12 dérniers mois"
..@ format.spss: chr "F1.0"
..@ labels : Named num [1:7] 0 1 2 3 4 5 9
.. ..- attr(*, "names")= chr [1:7] "Chômeur n'ayant jamais travaillé" "Inactif" "Salarié" "Indépendant" ...
>
Upvotes: 1
Views: 55
Reputation: 2827
You describe two basic steps (1) merge or join datasets (2) filter or mutate. See this test data:
authors <- data.frame(
## I(*) : use character columns of names to get sensible sort order
surname = I(c("Tukey", "Venables", "Tierney", "Ripley", "McNeil")),
nationality = c("US", "Australia", "US", "UK", "Australia"),
deceased = c("yes", rep("no", 4)))
authorN <- within(authors, { name <- surname; rm(surname) })
books <- data.frame(
name = I(c("Tukey", "Venables", "Tierney",
"Ripley", "Ripley", "McNeil", "R Core")),
title = c("Exploratory Data Analysis",
"Modern Applied Statistics ...",
"LISP-STAT",
"Spatial Statistics", "Stochastic Simulation",
"Interactive Data Analysis",
"An Introduction to R"),
other.author = c(NA, "Ripley", NA, NA, NA, NA,
"Venables & Smith"))
authors
> authors
surname nationality deceased
1 Tukey US yes
2 Venables Australia no
3 Tierney US no
4 Ripley UK no
5 McNeil Australia no
books
name title other.author
1 Tukey Exploratory Data Analysis <NA>
2 Venables Modern Applied Statistics ... Ripley
3 Tierney LISP-STAT <NA>
4 Ripley Spatial Statistics <NA>
5 Ripley Stochastic Simulation <NA>
6 McNeil Interactive Data Analysis <NA>
7 R Core An Introduction to R Venables & Smith
m1 <- merge(authors, books, by.x = "surname", by.y = "name")
m1
surname nationality deceased title other.author
1 McNeil Australia no Interactive Data Analysis <NA>
2 Ripley UK no Spatial Statistics <NA>
3 Ripley UK no Stochastic Simulation <NA>
4 Tierney US no LISP-STAT <NA>
5 Tukey US yes Exploratory Data Analysis <NA>
6 Venables Australia no Modern Applied Statistics ... Ripley
Say I only want authors from nationality
UK.
m1 %>% filter(nationality == "UK")
surname nationality deceased title other.author
1 Ripley UK no Spatial Statistics <NA>
2 Ripley UK no Stochastic Simulation <NA>
Each of your variables will work with either a filter
or a mutate
to create new dummy variables.
Upvotes: 1