[R] to delete lines by means of a vector
Arnaud Michel
michel.arnaud at cirad.fr
Tue Sep 10 17:03:56 CEST 2013
Hi
I would like to eliminate a large number of lines of the dataframe df1
The lines to delete are given here by the values of Mat (ex : 2,4,7,10).
but I have a large number (300) values of Mat
dput(df1)
structure(list(Mat = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3,
3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7,
7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10,
10, 11, 11, 11, 11, 11, 11, 11), Prenom = c("Ginette", "Ginette",
"Ginette", "Ginette", "Ginette", "Ginette", "Nicole", "Nicole",
"Nicole", "Nicole", "Jean", "Jean", "Jean", "Jean", "Jean", "Ginette",
"Ginette", "Ginette", "Ginette", "Ginette", "Hélène", "Hélène",
"Hélène", "Hélène", "Hélène", "Hélène", "Guy", "Guy", "Guy",
"Guy", "Guy", "Guy", "Claude", "Claude", "Claude", "Claude",
"Claude", "Claude", "Claude", "Régine", "Régine", "Régine", "Régine",
"Régine", "Régine", "Régine", "Germain", "Germain", "Germain",
"Germain", "Germain", "Germain", "Béatrice", "Béatrice", "Béatrice",
"Josette", "Josette", "Josette", "Josette", "Josette", "Josette",
"Josette"), Sexe = c("Féminin", "Féminin", "Féminin", "Féminin",
"Féminin", "Féminin", "Féminin", "Féminin", "Féminin", "Féminin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Féminin",
"Féminin", "Féminin", "Féminin", "Féminin", "Féminin", "Féminin",
"Féminin", "Féminin", "Féminin", "Féminin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Féminin",
"Féminin", "Féminin", "Féminin", "Féminin", "Féminin", "Féminin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Féminin", "Féminin", "Féminin", "Féminin", "Féminin", "Féminin",
"Féminin", "Féminin", "Féminin", "Féminin")), .Names = c("Mat",
"Prenom", "Sexe"), row.names = c(NA, 62L), class = "data.frame")
I would like to obtain the data frame df2
dput(df2)
structure(list(Mat = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3,
3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7,
7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10,
10, 11, 11, 11, 11, 11, 11, 11), Prenom = c("Ginette", "Ginette",
"Ginette", "Ginette", "Ginette", "Ginette", "Nicole", "Nicole",
"Nicole", "Nicole", "Jean", "Jean", "Jean", "Jean", "Jean", "Ginette",
"Ginette", "Ginette", "Ginette", "Ginette", "Hélène", "Hélène",
"Hélène", "Hélène", "Hélène", "Hélène", "Guy", "Guy", "Guy",
"Guy", "Guy", "Guy", "Claude", "Claude", "Claude", "Claude",
"Claude", "Claude", "Claude", "Régine", "Régine", "Régine", "Régine",
"Régine", "Régine", "Régine", "Germain", "Germain", "Germain",
"Germain", "Germain", "Germain", "Béatrice", "Béatrice", "Béatrice",
"Josette", "Josette", "Josette", "Josette", "Josette", "Josette",
"Josette"), Sexe = c("Féminin", "Féminin", "Féminin", "Féminin",
"Féminin", "Féminin", "Féminin", "Féminin", "Féminin", "Féminin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Féminin",
"Féminin", "Féminin", "Féminin", "Féminin", "Féminin", "Féminin",
"Féminin", "Féminin", "Féminin", "Féminin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Féminin",
"Féminin", "Féminin", "Féminin", "Féminin", "Féminin", "Féminin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Féminin", "Féminin", "Féminin", "Féminin", "Féminin", "Féminin",
"Féminin", "Féminin", "Féminin", "Féminin")), .Names = c("Mat",
"Prenom", "Sexe"), row.names = c(NA, 62L), class = "data.frame")
It is possible to obtain by
df2 <- df1[df1$Mat != 2 | df1$Mat !=4 | [df1$Mat !=7 | [df1$Mat !=10,]
But how to delete these lines when the 300 values of Mat are in the
vector MatDelete
Any ideas ?
--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31
More information about the R-help
mailing list