[R] Fwd: duplicates
ONKELINX, Thierry
Thierry.ONKELINX at inbo.be
Thu Jul 29 16:48:26 CEST 2010
Does this works? (Untested)
library(plyr)
ddply(your_dataframe, "var1", function(x){
x[which.max(x$var2), ]
})
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium
Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces op r-project.org
> [mailto:r-help-bounces op r-project.org] Namens Dévaványai Agamemnón
> Verzonden: donderdag 29 juli 2010 16:31
> Aan: r-help op r-project.org
> Onderwerp: [R] Fwd: duplicates
>
>
>
> -- Eredeti üzenet --
> Feladó: Dévaványai Agamemnón
> <devavanyai op citromail.hu>Címzett: r-hel op r-project.org,
> r-hel op r-project.orgElküldve: 2010. július 29. 16:29Tárgy : duplicates
>
> 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]]
>
>
Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in this message
and any annex are purely those of the writer and may not be regarded as stating
an official position of INBO, as long as the message is not confirmed by a duly
signed document.
More information about the R-help
mailing list