[R] data.frame operations

Nicolas Gutierrez nicolasg at uw.edu
Fri Feb 25 22:01:53 CET 2011


Hi All,

I've been doing circles with this all morning, although I'm sure there's 
a simple solution. I have a data.frame "pop" as follows:

 > pop

    ind	xloc  yloc  gonad
1   1	 5     2     12
2   1	 5     4     25
3   1	 3     3     30
4   1	 5     4     10
5   1	 1     4     08
.   .    .     .      .
10  1	 1     4     11

And I need the following steps:

1. Sum "gonad" by combining (xloc, yloc) as follows and create 
data.frame "fish":

 > fish

    ind	xloc  yloc  gonad
1   1	  5     2     12
2   2     5     4     35
3   1	  3     3     30
4   2     1     4     19

2. Extract the 2 highest values of "gonad":

 > new.fish

    ind	xloc  yloc  gonad
1   2	 5     4     35
2   1	 3     3     31

3. Delete "fish" from "pop" (2 data.frames).

Hope you get the idea and thanks for any help!!

Nico



More information about the R-help mailing list