[R] sub setting data.frame

Nicolas Gutierrez nicolasg at uw.edu
Mon Feb 28 21:20:07 CET 2011


Got it.. thanks to Jorge!

pop[1:which(with(pop, cumsum(cell) == 2)),]

Nico

2/28/2011 12:08 PM, Ista Zahn wrote:
> I don't understand the question...
>
> On Mon, Feb 28, 2011 at 2:46 PM, Nicolas Gutierrez<nicolasg at uw.edu>  wrote:
>> Hi All,
>>
>> I have a data.frame:
>>
>>> pop
>>
>>     consumed ind recruits   gonad cell
>> 1    516.74   1     0.02    20.21 0.25
>> 2   1143.20   1     0.02    20.21 0.50
>> 3    250.00   1     0.02    20.21 0.25
>> 4    251.98   1     0.02    18.69 0.25
>> 5    598.08   1     0.02    18.69 0.25
>> 6    437.38   1     0.02    18.69 0.25
>> 7    250.00   1     0.02    17.39 0.25
>> 8    250.00   1     0.02    17.39 0.25
>> 9    250.00   1     0.02    17.39 0.25
>> 10   257.07   1     0.02    16.02 0.25
>>
>> And I need to get the number of rows that sums a particular value (e.g. 2).
>
> OK so you want the numer of rows where what sums to 2?
>
>>
>> In my case above it would be 4 (the first 4 rows ==>  sum(pop$cell)=2.
>
> Ah, where cell sums to 2. Except that in the first 4 rows cell sums to 1.25...
>
> Confused!
>
> Can you clarify your question?
>
> Best,
> Ista
>
>>
>> Any ideas?
>> THANKS
>>
>> Nico
>>
>>
>> --
>>
>> Nicolas L. Gutierrez
>>
>> School of Aquatic and Fishery Sciences
>> 1122 NE Boat St, Seattle, WA 98105
>>
>> Lab:    +1 206 221 5457
>> Home:   +1 206 290 3858
>> www.fish.washington.edu
>>
>> ______________________________________________
>> 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.
>>
>
>
>


-- 

Nicolas L. Gutierrez

School of Aquatic and Fishery Sciences
1122 NE Boat St, Seattle, WA 98105

Lab: 	+1 206 221 5457
Home: 	+1 206 290 3858
www.fish.washington.edu



More information about the R-help mailing list