[R] delete some lines of a dataframe

Arnaud Michel michel.arnaud at cirad.fr
Tue Sep 17 20:14:52 CEST 2013


Hi

I have a dataframe Df1
dput(Df1)
structure(list(Mat = c(141, 141, 157, 157, 188, 188, 232, 232,
253, 253, 253, 254, 254, 254, 254, 256, 256, 264, 264), Prenom = 
c("Pierre",
"Pierre", "Jean-Claude", "Jean-Claude", "Jean-Louis", "Jean-Louis",
"Philippe", "Philippe", "Christophe", "Christophe", "Christophe",
"Dominique", "Dominique", "Dominique", "Dominique", "Pierre-Luc",
"Pierre-Luc", "Alain", "Alain"), Sexe = c("Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin"),
     DateNais = c("23/08/1946", "23/08/1946", "11/08/1945", "11/08/1945",
     "09/04/1948", "09/04/1948", "01/05/1946", "01/05/1946", "11/02/1951",
     "11/02/1951", "11/02/1951", "21/10/1949", "21/10/1949", "21/10/1949",
     "21/10/1949", "25/06/1946", "25/06/1946", "13/03/1949", "13/03/1949"
     )), .Names = c("Mat", "Prenom", "Sexe", "DateNais"), row.names = 
c("207",
"208", "232", "233", "288", "289", "373", "374", "412", "413",
"414", "415", "416", "417", "418", "420", "421", "436", "437"
), class = "data.frame")

I want to extract of Df1 2 other dataframes :
1) delete the first line for each values of Mat
        Mat      Prenom     Sexe   DateNais
208 141      Pierre Masculin 23/08/1946
233 157 Jean-Claude Masculin 11/08/1945
289 188  Jean-Louis Masculin 09/04/1948
374 232    Philippe Masculin 01/05/1946
413 253  Christophe Masculin 11/02/1951
414 253  Christophe Masculin 11/02/1951
416 254   Dominique Masculin 21/10/1949
417 254   Dominique Masculin 21/10/1949
418 254   Dominique Masculin 21/10/1949
421 256  Pierre-Luc Masculin 25/06/1946
437 264       Alain Masculin 13/03/1949

2) delete the last line for each values of Mat
     Mat      Prenom     Sexe   DateNais
207 141      Pierre Masculin 23/08/1946
232 157 Jean-Claude Masculin 11/08/1945
288 188  Jean-Louis Masculin 09/04/1948
373 232    Philippe Masculin 01/05/1946
412 253  Christophe Masculin 11/02/1951
413 253  Christophe Masculin 11/02/1951
415 254   Dominique Masculin 21/10/1949
416 254   Dominique Masculin 21/10/1949
417 254   Dominique Masculin 21/10/1949
420 256  Pierre-Luc Masculin 25/06/1946
436 264       Alain Masculin 13/03/1949

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