[R] delete some lines of a dataframe
Arnaud Michel
michel.arnaud at cirad.fr
Wed Sep 18 08:11:01 CEST 2013
Merci Arun
Michel
Le 17/09/2013 22:41, arun a écrit :
>
> Hi Arnaud,
> You could also try:
> indx<- Df1$Mat[-1]==Df1$Mat[-nrow(Df1)]
> indx1<-c(indx,FALSE)
> indx2<-c(FALSE,indx)
>
> Df1[indx1,]
> Df1[indx2,]
> A.K.
>
>
>
> ________________________________
> From: arun <smartpink111 at yahoo.com>
> To: Arnaud Michel <michel.arnaud at cirad.fr>
> Cc: R help <r-help at r-project.org>
> Sent: Tuesday, September 17, 2013 4:21 PM
> Subject: Re: [R] delete some lines of a dataframe
>
>
> Hi Arnaud,
>
> In that case:
>
> Try:
> Df1[duplicated(Df1$Mat),]
> Df1[duplicated(Df1$Mat,fromLast=TRUE),]
>
> #or
>
>
> A.K.
>
>
> ----- Original Message -----
> From: Arnaud Michel <michel.arnaud at cirad.fr>
> To: arun <smartpink111 at yahoo.com>
> Cc: R help <r-help at r-project.org>
> Sent: Tuesday, September 17, 2013 4:00 PM
> Subject: Re: [R] delete some lines of a dataframe
>
> Thank you Arun
> but the values of other columns may be different !!!
> Michel
> Le 17/09/2013 20:56, arun a écrit :
>> Hi,
>> Try:
>> Df1[duplicated(Df1),]
>> Df1[duplicated(Df1,fromLast=TRUE),]
>> A.K.
>>
>>
>>
>> ----- Original Message -----
>> From: Arnaud Michel <michel.arnaud at cirad.fr>
>> To: R help <r-help at r-project.org>
>> Cc:
>> Sent: Tuesday, September 17, 2013 2:14 PM
>> Subject: [R] delete some lines of a dataframe
>>
>> 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
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
--
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