exo<-read.table("sexepoidstaille.txt",sep = "", header = TRUE)
str(exo)
## 'data.frame': 66 obs. of 3 variables:
## $ sexe: Factor w/ 2 levels "f","h": 2 1 1 1 1 1 1 2 1 2 ...
## $ poi : int 60 57 51 55 50 50 48 72 52 64 ...
## $ tai : int 170 169 172 174 168 161 162 189 160 175 ...
exo[c(1,5,55),]
## sexe poi tai
## 1 h 60 170
## 5 f 50 168
## 55 h 73 171
exo[c(1:10),2:3] # on effache la variable sexe
## poi tai
## 1 60 170
## 2 57 169
## 3 51 172
## 4 55 174
## 5 50 168
## 6 50 161
## 7 48 162
## 8 72 189
## 9 52 160
## 10 64 175
exo[c(seq(1,66,4)),]
## sexe poi tai
## 1 h 60 170
## 5 f 50 168
## 9 f 52 160
## 13 h 61 175
## 17 f 53 164
## 21 f 49 158
## 25 f 53 170
## 29 f 70 172
## 33 h 76 178
## 37 f 53 163
## 41 h 75 180
## 45 h 55 173
## 49 h 71 181
## 53 h 62 168
## 57 h 60 174
## 61 h 82 188
## 65 f 47 150
exo[exo$sexe=="f",]
## sexe poi tai
## 2 f 57 169
## 3 f 51 172
## 4 f 55 174
## 5 f 50 168
## 6 f 50 161
## 7 f 48 162
## 9 f 52 160
## 11 f 53 165
## 16 f 51 158
## 17 f 53 164
## 21 f 49 158
## 22 f 50 163
## 25 f 53 170
## 29 f 70 172
## 30 f 62 174
## 34 f 51 168
## 35 f 52 170
## 36 f 57 160
## 37 f 53 163
## 38 f 55 168
## 39 f 66 172
## 42 f 50 162
## 43 f 53 177
## 54 f 47 161
## 65 f 47 150
exo$tai[exo$tai>175] #pas de virgule parce qu'il y a 1 seul colonne
## [1] 189 184 178 179 182 185 178 180 189 200 178 178 180 177 182 183 184 181 180
## [20] 178 178 180 182 181 188 182 189 178 186
Ici on affiche les tailles avec les autres variables - !!! Faire attention aux différences de notation
exo[exo$tai>175,]
## sexe poi tai
## 8 h 72 189
## 14 h 78 184
## 15 h 68 178
## 18 h 79 179
## 19 h 74 182
## 24 h 80 185
## 26 h 73 178
## 27 h 70 180
## 28 h 72 189
## 31 h 77 200
## 32 h 70 178
## 33 h 76 178
## 41 h 75 180
## 43 f 53 177
## 46 h 72 182
## 47 h 75 183
## 48 h 73 184
## 49 h 71 181
## 50 h 66 180
## 51 h 71 178
## 52 h 79 178
## 56 h 72 180
## 59 h 85 182
## 60 h 73 181
## 61 h 82 188
## 62 h 86 182
## 63 h 85 189
## 64 h 65 178
## 66 h 74 186
exo[exo$sexe=="f" & exo$tai>175,]
## sexe poi tai
## 43 f 53 177
On crée la nouvelle variable “taic” - la colonne tai est dupliquée dans la nouvelle colonne.
On remplace par 175 avec le “<-” on peut faire cette étape sans passer parcelle de dessus.
On vérifie que la nouvelle variable a été créée et que le remplacement a bien marché
exo$taic<-exo$tai
exo$taic[exo$tai>175]<-175
exo
## sexe poi tai taic
## 1 h 60 170 170
## 2 f 57 169 169
## 3 f 51 172 172
## 4 f 55 174 174
## 5 f 50 168 168
## 6 f 50 161 161
## 7 f 48 162 162
## 8 h 72 189 175
## 9 f 52 160 160
## 10 h 64 175 175
## 11 f 53 165 165
## 12 h 72 164 164
## 13 h 61 175 175
## 14 h 78 184 175
## 15 h 68 178 175
## 16 f 51 158 158
## 17 f 53 164 164
## 18 h 79 179 175
## 19 h 74 182 175
## 20 h 62 174 174
## 21 f 49 158 158
## 22 f 50 163 163
## 23 h 74 172 172
## 24 h 80 185 175
## 25 f 53 170 170
## 26 h 73 178 175
## 27 h 70 180 175
## 28 h 72 189 175
## 29 f 70 172 172
## 30 f 62 174 174
## 31 h 77 200 175
## 32 h 70 178 175
## 33 h 76 178 175
## 34 f 51 168 168
## 35 f 52 170 170
## 36 f 57 160 160
## 37 f 53 163 163
## 38 f 55 168 168
## 39 f 66 172 172
## 40 h 65 175 175
## 41 h 75 180 175
## 42 f 50 162 162
## 43 f 53 177 175
## 44 h 55 169 169
## 45 h 55 173 173
## 46 h 72 182 175
## 47 h 75 183 175
## 48 h 73 184 175
## 49 h 71 181 175
## 50 h 66 180 175
## 51 h 71 178 175
## 52 h 79 178 175
## 53 h 62 168 168
## 54 f 47 161 161
## 55 h 73 171 171
## 56 h 72 180 175
## 57 h 60 174 174
## 58 h 67 175 175
## 59 h 85 182 175
## 60 h 73 181 175
## 61 h 82 188 175
## 62 h 86 182 175
## 63 h 85 189 175
## 64 h 65 178 175
## 65 f 47 150 150
## 66 h 74 186 175