[R] subset data frame with condition

Nicolas Gutierrez nicolasg at uw.edu
Fri Mar 18 18:48:44 CET 2011


Hello,

One more question.. I have the data.frame "pop":

     xloc yloc  gonad  ind    Ene    W   Area
1    23  20   516.74   1     0.02 20.21  1
2    23  20  1143.20   1     0.02 20.21  1
3    23  20   250.00   1     0.02 20.21  1
4    22  15   251.98   1     0.02 18.69  2
5    22  15   598.08   1     0.02 18.69  2
6    21  19   250.00   1     0.02 20.21  3
7    22  20   251.98   1     0.02 18.69  4
8    22  20   598.08   1     0.02 18.69  4

and I need to extract 50% (or rounded) of the rows for each Area (from 
Area 1 to 3 only):

     xloc yloc  gonad  ind    Ene    W   Area
1    23  20   516.74   1     0.02 20.21  1
2    23  20  1143.20   1     0.02 20.21  1
4    22  15   251.98   1     0.02 18.69  2
6    21  19   250.00   1     0.02 20.21  3

I did this within a loop, but considering my data.frame has more than 
10,000 rows and within other loops it makes my code run forever! Any 
hints? Thanks!!

Nico



More information about the R-help mailing list