[R-sig-eco] Subset dataframe

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Tue Apr 16 15:20:16 CEST 2013


Something like this?

cpueData[ave(cpueData$LRVS_cpue, cpueData$outingID, FUN = max) == cpueData$LRVS_cpue, ]

untest since you didn't provide some easy to copy-and-paste dataset. Use the output of dput(sample.data.frame) to provide sample data

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx at 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-sig-ecology-bounces at r-project.org [mailto:r-sig-ecology-bounces at r-project.org] Namens Jade Maggs
Verzonden: dinsdag 16 april 2013 14:13
Aan: r-sig-ecology at r-project.org
Onderwerp: [R-sig-eco] Subset dataframe

Hi list, I need to subset the dataframe below by selecting rows with maximum LRVS_cpue values for each outing_ID. For example, where outing_ID == 51801, the new dataframe should have only one row with LRVS_cpue = 0.5. LRVS_cpue in all other rows should remain as 0. I have over 650 000 rows, so looping is very slow.



I have tried: >cpueData1 <-
data.frame(unique(cpueData[max(cpueData$LRVS_cpue),])) but this does not work.



Any help would be greatly appreciated.






patrol_ID

outing_ID

num_anglers

hours_fish

ang_hours

LRVS_cpue


51709

51795

2

3.5

7

0


51709

51796

1

0.5

0.5

0


51709

51797

1

1

1

0


51709

51798

1

2

2

0


51709

51799

5

5.5

27.5

0


51709

51800

1

3

3

0


51709

51801

2

1

2

0


51709

51801

2

1

2

0.5


51709

51802

1

1.5

1.5

0


51709

51803

3

1

3

0


51709

51804

4

1

4

0



JADE MAGGS

Assistant Scientist


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
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-sig-ecology mailing list