[R] duplicates

Jannis bt_jannis at yahoo.de
Thu Jul 29 21:38:17 CEST 2010


There is most probably a function doing exactly this, but i would give 
this solution a try:


dataframe=dataframe[order(dataframe[,1],-dataframe[,2]),]

kept.rows<-which(diff(dataframe[,1])+1

new.dataframe <- dataframe[kept.rows,]

Dévaványai Agamemnón schrieb:
>   Sorry!
> I try it again
>
> Dear R Users!
>
>
> I have a dataframe with duplicatecases. Var1 duplicated by var2. 
>
>
>
> var1 var2  var3  var4  var5
> 1        4       500     1    2
> 1        3       200     2    5
> 1        8       125     1    9
> 2        2       120     2    52
> 2        6        22      1    20
> 2        9        400    1    22
> 3        1        100    2    8
> 3        2        200    5    40
> 4        8        20      1    60
>
> I want to delete duplicate ones from var1 which have low rank at var2, and keep that case which has highest rank at var2. I would like to keep the Whole row (with the other variables: 
>
> var1     var2     var3    var4    var5    
> 1          8          125     1         9
> 2          9           400    1        22
> 3          2           200    50     40
> 4           8          200     1      60 Thanks Ag 
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
>



More information about the R-help mailing list