Re: [R] simple subset question

2012-12-02 Thread Felipe Carrillo
I finally see what you and David W mean...I was under the assumption that by 
subsetting
Year==2012 it would also extract the max for that year.I guess I have to 
review 'subset' again :)
Thank you much 

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



>
>From: David L Carlson 
>To: 'Felipe Carrillo' ; 'arun' 
> 
>Cc: 'R help'  
>Sent: Sunday, December 2, 2012 2:54 PM
>Subject: RE: [R] simple subset question
>
>As David W. guessed. The maximum is in year 2005 not 2012 so no row from
>2012 matches the maximum.
>
>> subset(winter,Year==2012 & Total==max(Total))
>[1] IDWeek Total  Fry    Smolt  FryEq  Year  
><0 rows> (or 0-length row.names)
>> winter[which(winter$Total==max(winter$Total)),]
>    IDWeek  Total    Fry Smolt  FryEq Year
>195    39 2115018 2083214 31805 2137281 2005
>
>Change to
>
>> subset(winter, Year==2012 & Total==max(Total[Year==2012]))
>  IDWeek  Total  Fry  Smolt  FryEq Year
>21    47 303259 34008 269248 491733 2012
>
>--
>David L Carlson
>Associate Professor of Anthropology
>Texas A&M University
>College Station, TX 77843-4352
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Felipe Carrillo
>> Sent: Sunday, December 02, 2012 4:40 PM
>> To: arun
>> Cc: R help
>> Subject: Re: [R] simple subset question
>> 
>> Actually, I dput(winter) and is not that big.so here is the whole
>> thing I
>> am trying to accomplish.
>>  winter <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
>> 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
>> 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
>> 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
>> 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
>> 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
>> 13221L, 4894L, 0L, 460L, 1129L, 1757L, 11105L, 27730L, 55769L,
>> 12298L, 32964L, 80110L, 160507L, 74134L, 101736L, 138355L, 107873L,
>> 53806L, 194429L, 7596L, 55497L, 30336L, 18392L, 22291L, 16850L,
>> 16567L, 14799L, 7909L, 93L, 329L, 363L, 2762L, 5573L, 33466L,
>> 96762L, 340947L, 612835L, 347972L, 526506L, 656981L, 344181L,
>> 145465L, 150543L, 935599L, 32789L, 15092L, 7288L, 9889L, 6945L,
>> 5138L, 6299L, 3095L, 108227L, 1191L, 0L, 0L, 132L, 227L, 2157L,
>> 7558L, 16459L, 87220L, 321195L, 209299L, 110807L, 112024L, 128058L,
>> 74373L, 41531L, 15111L, 21890L, 15060L, 22538L, 12443L, 11052L,
>> 3907L, 2640L, 2745L, 3936L, 17593L, 0L, 0L, 10775L, 4166L, 4958L,
>> 16221L, 29401L, 34951L, 33188L, 146044L, 105007L, 185297L, 159682L,
>> 207537L, 140694L, 128275L, 44274L, 27079L, 18928L, 10437L, 29984L,
>> 18395L, 25846L, 4573L, 31995L, 3679L, 707L, 2390L, 8860L, 24430L,
>> 40885L, 72792L, 205521L, 344493L, 662973L, 526409L, 631953L,
>> 850491L, 84

Re: [R] simple subset question

2012-12-02 Thread David L Carlson
As David W. guessed. The maximum is in year 2005 not 2012 so no row from
2012 matches the maximum.

> subset(winter,Year==2012 & Total==max(Total))
[1] IDWeek Total  FrySmolt  FryEq  Year  
<0 rows> (or 0-length row.names)
> winter[which(winter$Total==max(winter$Total)),]
IDWeek   Total Fry Smolt   FryEq Year
195 39 2115018 2083214 31805 2137281 2005

Change to

> subset(winter, Year==2012 & Total==max(Total[Year==2012]))
   IDWeek  Total   Fry  Smolt  FryEq Year
21 47 303259 34008 269248 491733 2012

--
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Felipe Carrillo
> Sent: Sunday, December 02, 2012 4:40 PM
> To: arun
> Cc: R help
> Subject: Re: [R] simple subset question
> 
> Actually, I dput(winter) and is not that big.so here is the whole
> thing I
> am trying to accomplish.
>  winter <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
> 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
> 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
> 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
> 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
> 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
> 13221L, 4894L, 0L, 460L, 1129L, 1757L, 11105L, 27730L, 55769L,
> 12298L, 32964L, 80110L, 160507L, 74134L, 101736L, 138355L, 107873L,
> 53806L, 194429L, 7596L, 55497L, 30336L, 18392L, 22291L, 16850L,
> 16567L, 14799L, 7909L, 93L, 329L, 363L, 2762L, 5573L, 33466L,
> 96762L, 340947L, 612835L, 347972L, 526506L, 656981L, 344181L,
> 145465L, 150543L, 935599L, 32789L, 15092L, 7288L, 9889L, 6945L,
> 5138L, 6299L, 3095L, 108227L, 1191L, 0L, 0L, 132L, 227L, 2157L,
> 7558L, 16459L, 87220L, 321195L, 209299L, 110807L, 112024L, 128058L,
> 74373L, 41531L, 15111L, 21890L, 15060L, 22538L, 12443L, 11052L,
> 3907L, 2640L, 2745L, 3936L, 17593L, 0L, 0L, 10775L, 4166L, 4958L,
> 16221L, 29401L, 34951L, 33188L, 146044L, 105007L, 185297L, 159682L,
> 207537L, 140694L, 128275L, 44274L, 27079L, 18928L, 10437L, 29984L,
> 18395L, 25846L, 4573L, 31995L, 3679L, 707L, 2390L, 8860L, 24430L,
> 40885L, 72792L, 205521L, 344493L, 662973L, 526409L, 631953L,
> 850491L, 842678L, 445987L, 558152L, 332032L, 174326L, 80601L,
> 48696L, 98571L, 103563L, 149469L, 78081L, 182478L, 2158L, 16566L,
> 0L, 868L, 2044L, 4064L, 6049L, 9399L, 13304L, 45172L, 242155L,
> 476864L, 712534L, 1058409L, 2115018L, 1510342L, 1138213L, 333192L,
> 158820L, 94379L, 348882L, 39290L, 29701L, 47258L, 69837L, 7884L,
> 49338L, 22168L, 0L, 147L, 1231L, 3216L, 5021L, 18462L, 37441L,
> 64669L, 136590L, 338523L, 559448L, 714837L, 358037L, 180910L,
> 291943L, 222708L, 163801L, 39109L, 23247L, 15726L, 38701L, 5795L,
> 12509L, 18721L, 822L, 6674L, 765L, 1753L, 6226L, 9727L, 22033L,
> 50472L, 67863L, 100909L, 276699L, 239609L, 416465L, 845073L,
> 1071051L, 571656L, 409021L, 451331L, 167006L, 68069L, 250439L,
> 104641L, 76062L, 35261L, 55883L, 16064L, 11058L, 8872L, 9346L,
> 24760L, 41699L, 40032L, 80576L, 152208L, 171888L, 292862L, 522669L,
> 441518L, 858538L, 906010L, 1464311L, 1334433L,

Re: [R] simple subset question

2012-12-02 Thread Felipe Carrillo
12L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2009L, 2009L, 2009L, 2009L,
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L,
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L,
2009L, 2009L, 2009L, 2009L, 2008L, 2008L, 2008L, 2008L, 2008L,
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L,
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L,
2008L, 2008L, 2008L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L,
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L,
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L,
2006L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L,
2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L,
2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L,
2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L,
2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L,
2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2003L,
2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L,
2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L,
2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2002L, 2002L,
2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L,
2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L,
2002L, 2002L, 2002L, 2002L, 2002L, 2002L)), .Names = c("IDWeek",
"Total", "Fry", "Smolt", "FryEq", "Year"), class = "data.frame", row.names = 
c(NA,
-286L))
 library(ggplot2)
 library(plyr)
 dim(winter);head(winter)
   str(winter)
 test <- ggplot(winter,aes(IDWeek,Total)) + geom_line(colour='blue') + 
facet_wrap(~Year,as.table=F) +
  geom_vline(xintercept=47,colour='red',linetype='dashed')  +
   geom_hline(yintercept=30,colour='orange',linetype='dashed',size=1)  +
   opts(title="Winter Chinook 2002-2012")  +
   geom_point(data=subset(winter,Year==2012 & 
Total==max(Total)),size=7,shape=1,color='green') # Want to be able to subset 
using max on the fly
   
test
 # But it doesn't subset at all
   
   # It works if I get the max Total like this:
   test <- ggplot(winter,aes(IDWeek,Total)) + geom_line(colour='blue') + 
facet_wrap(~Year,as.table=F) +
  geom_vline(xintercept=47,colour='red',linetype='dashed')  +
   geom_hline(yintercept=30,colour='orange',linetype='dashed',size=1)  +
   opts(title="Winter Chinook 2002-2012")  +
   geom_point(data=subset(winter,Year==2012 & Total > 
30),size=7,shape=1,color='green') # it works if get the Total like this
   test

    # Zooming in to the weeks of interest (weeks 45 to 52) and put a point on 
the 2012 max catch which is week 37
    windows()
  test + coord_cartesian(xlim=c(45,52)) + 
scale_x_continuous(breaks=c(45,47,49,51)) +
  scale_y_continuous(limits=c(0,35)) + opts(title="Zooming in to weeks 45 
to 52")
 
 
 

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



>
>From: arun 
>To: Felipe Carrillo  
>Cc: William Dunlap ; David Winsemius 
>; R help  
>Sent: Sunday, December 2, 2012 1:18 PM
>Subject: Re: [R] simple subset question
>
>Hi,
>From the ddply() output, you could get the whole row by:
>
> fish1 <- structure(list(Year = 2002:2012, maxTotal = c(1464311L, 1071051L, 
>714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L, 
>157260L, 303259L)), .Names = c("Year", "maxTotal"), row.names = c(NA, 
>-11L), class = "data.frame")
>
>
> fish[fish[,2]%in%fish1[,2][fish1[,1]==2012],]  #fish (or winter) is your 
>original dataset
>#   IDWeek  Total   Fry  Smolt  FryEq Year
>#21 47 303259 34008 269248 491733 2012
>A.K.
>
>
>
>
>
>
>From: Felipe Carrillo 
>To: William Dunlap ; arun  
>Cc: R help  
>Sent: Sunday, December 2, 2012 2:34 PM
>Subject: Re: [R] simple sub

Re: [R] simple subset question

2012-12-02 Thread arun
Hi,
>From the ddply() output, you could get the whole row by:

 fish1 <- structure(list(Year = 2002:2012, maxTotal = c(1464311L, 1071051L, 
714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L, 
157260L, 303259L)), .Names = c("Year", "maxTotal"), row.names = c(NA, 
-11L), class = "data.frame")


 fish[fish[,2]%in%fish1[,2][fish1[,1]==2012],]  #fish (or winter) is your 
original dataset
#   IDWeek  Total   Fry  Smolt  FryEq Year
#21 47 303259 34008 269248 491733 2012
A.K.






From: Felipe Carrillo 
To: William Dunlap ; arun  
Cc: R help  
Sent: Sunday, December 2, 2012 2:34 PM
Subject: Re: [R] simple subset question



Using my whole dataset I get:
library(plyr)
ddply(winter,"Year",summarise,maxTotal=max(Total))

 fish <- structure(list(Year = 2002:2012, maxTotal = c(1464311L, 1071051L, 
714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L, 
157260L, 303259L)), .Names = c("Year", "maxTotal"), row.names = c(NA, 
-11L), class = "data.frame")

I only want to extract the max Total for 2012 and want the whole row like this:
 IDWeek  Total   Fry  Smolt  FryEq Year
21 47 303259 34008 269248 491733 2012

My whole dataset is too big to post it so thanks for your help and will try
to figure out why subset returns an empty row

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



From: William Dunlap 
>To: Felipe Carrillo ; arun  
>Cc: R help  
>Sent: Sunday, December 2, 2012 11:00 AM
>Subject: RE: [R] simple subset question
>
>> I am
>> still getting an error message
>> >with :
>> >  x <- subset(fish,Year==2012
& Total==max(Total));x
>> >I get:
>> >[1] IDWeek Total  Fry    Smolt  FryEq  Year
>> ><0 rows> (or 0-length row.names)
>
>The above is not an error message.  It says that there
>are no rows satisfying your criteria.  Note that Total==max(Total)
>returns a TRUE for each row in which the Total value
>equals the maximum Total value over all the years in
>the data.  Are you looking for the maximum value of Total
>in each year?
>
>> tmp <- transform(fish, YearlyMaxTotal = ave(Total, Year, FUN=max))
>> subset(tmp, Total==YearlyMaxTotal)
>  IDWeek  Total    Fry  Smolt  FryEq Year YearlyMaxTotal
>21    47 303259  34008 269248 491733 2012        303259
>39    39 157260 156909    351 157506 2011        157260
>> subset(tmp, Total==YearlyMaxTotal
& Year==2012)
>  IDWeek  Total  Fry  Smolt  FryEq Year YearlyMaxTotal
>21    47 303259 34008 269248 491733 2012        303259
>
>Bill Dunlap
>Spotfire, TIBCO Software
>wdunlap tibco.com
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
>> Behalf
>> Of Felipe Carrillo
>> Sent: Sunday, December 02, 2012 10:47 AM
>> To: arun
>> Cc: R help
>> Subject: Re: [R] simple subset question
>> 
>> Works with the small dataset (2 years) but I get the error message with the 
>> whole
>> dataset (12 years of data). I am going to have
>> to check what's
wrong with it...Thanks
>> 
>> Felipe D. Carrillo
>> Supervisory Fishery Biologist
>> Department of the Interior
>> US Fish & Wildlife Service
>> California, USA
>> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>> 
>> 
>> From: arun 
>> >To: Felipe Carrillo 
>> >Cc: R help ; R. Michael Weylandt
>> 
>> >Sent: Sunday, December 2, 2012 10:29 AM
>> >Subject: Re: [R] simple subset question
>> >
>>
>Hi,
>> >I am getting this:
>> >x<-subset(fish,Year==2012 & Total==max(Total))
>> > x
>> >#   IDWeek  Total   Fry  Smolt  FryEq Year
>> >#21 47 303259 34008 269248 491733 2012
>> >A.K.
>> >
>> >
>> >
>> >
>> >- Original Message -
>> >From: Felipe Carrillo 
>> >To: R. Michael Weylandt 
>> >Cc: "r-help@r-project.org" 
>> >Sent:
Sunday, December 2, 2012 1:25 PM
>> >Subject: Re: [R] simple subset question
>> >
>> >Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
>> >forgot to
>> change the variable names
>> >when I asked the question. David W suggestion works but the strange part is 
>> >that I am
>> still getting an error message
>> >with :
>> >  x <- subset(fish,Year==2012 & Total==max(Total));x
>> >I get:
>> >[1] IDWeek Total  Fry    Smolt  FryEq  Year
>> >&l

Re: [R] simple subset question

2012-12-02 Thread arun
Hi,
I am getting this:
x<-subset(fish,Year==2012 & Total==max(Total))
 x
#   IDWeek  Total   Fry  Smolt  FryEq Year
#21 47 303259 34008 269248 491733 2012
A.K.




- Original Message -
From: Felipe Carrillo 
To: R. Michael Weylandt 
Cc: "r-help@r-project.org" 
Sent: Sunday, December 2, 2012 1:25 PM
Subject: Re: [R] simple subset question

Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
forgot to change the variable names
when I asked the question. David W suggestion works but the strange part is 
that I am still getting an error message
with :
  x <- subset(fish,Year==2012 & Total==max(Total));x
I get:
[1] IDWeek Total  Fry    Smolt  FryEq  Year  
<0 rows> (or 0-length row.names)
 
I will start a fresh session to see if that helps...Thank you all

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: R. Michael Weylandt 
>To: Felipe Carrillo  
>Cc: "r-help@r-project.org"  
>Sent: Sunday, December 2, 2012 9:42 AM
>Subject: Re: [R] simple subset question
>
>On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
> wrote:
>>  Hi,
>> Consider the small dataset below, I want to subset by two variables in
>> one line but it wont work...it works though if I subset separately. I have
>> to be missing something obvious that I did not realize before while using 
>> subset..
>>
>> fish <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
>> 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
>> 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
>> 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
>> 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
>> 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
>> 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
>> 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
>> 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
>> 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
>> 30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
>> 1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
>> 0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
>> 23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
>> 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
>> 905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
>> 31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
>> 1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
>> 94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
>> 33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
>> 13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
>> 53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
>> 22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
>> 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
>> 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
>> 2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
>> 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
>> 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
>> 2011L)), .Names = c("IDWeek", "Total", "Fry", "Smolt", "FryEq",
>> "Year"), row.names = c(NA, 52L), class = "data.frame")
>> fish
>> #  Subset to get the max Total for 2012
>>  x <- subset(winter,Year==2012 & Total==max(Total));b  # How come one line 
>>doesn't work?
>
>Works fine for me if I change "winter" to fish here.
>
>subset(fish,Year==2012 & Total==max(Total))
>  IDWeek  Total  Fry  Smolt  FryEq Year
>21    47 303259 34008 269248 491733 2012
>
>>
>>  # It works if I subset the year first and then get the Total max from it
>>  xx <- subset(winter,Year==2012)
>> xxx <- subset(xx,Total==max(Total));xxx
>> xxx
>>
>> Felipe D. Carrillo
>> Supervisory Fishery Biologist
>> Department of the Interior
>> US Fish & Wildlife Service
>> California, USA
>> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>>
>>        [[alternat

Re: [R] simple subset question

2012-12-02 Thread Felipe Carrillo
I also thought that I could use it but ggplot didn't like it by itself,,,it 
wants to whole rowI guess it is hard
to understand because I didn't post all the ggplot code of what I am trying to 
accomplish. The strangest thing is that
ddply can extract all my Totals by year but when I try to subset only one year 
out of my whole dataset, it returns
empty rows it regardless of what year I am subsetting. I am doing  a few tests 
to see what's going on

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: David Winsemius 
>To: Felipe Carrillo  
>Cc: William Dunlap ; arun ; R help 
> 
>Sent: Sunday, December 2, 2012 11:54 AM
>Subject: Re: [R] simple subset question
>
>The reason I suggested the alternative that I did was because your code could 
>fail when the max(Total) value was not in the subset where Year==2012.
>
>--David
>On Dec 2, 2012, at 11:34 AM, Felipe Carrillo wrote:
>
>> 
>> Using my whole dataset I get:
>> library(plyr)
>> ddply(winter,"Year",summarise,maxTotal=max(Total))
>> 
>>  fish <- structure(list(Year = 2002:2012, maxTotal = c(1464311L, 1071051L,
>> 714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L,
>> 157260L, 303259L)), .Names = c("Year", "maxTotal"), row.names = c(NA,
>> -11L), class = "data.frame")
>> 
>> I only want to extract the max Total for 2012 and want the whole row like 
>> this:
>>  IDWeek  Total  Fry  Smolt  FryEq Year
>> 21    47 303259 34008 269248 491733 2012
>> 
>> My whole dataset is too big to post it so thanks for your help and will try
>> to figure out why subset returns an empty row
>> 
>> Felipe D. Carrillo
>> Supervisory Fishery Biologist
>> Department of the Interior
>> US Fish & Wildlife Service
>> California, USA
>> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>> 
>> 
>> From: William Dunlap 
>>> To: Felipe Carrillo ; arun 
>>> 
>>> Cc: R help 
>>> Sent: Sunday, December 2, 2012 11:00 AM
>>> Subject: RE: [R] simple subset question
>>> 
>>>> I am
>>>> still getting an error message
>>>>> with :
>>>>>  x <- subset(fish,Year==2012 & Total==max(Total));x
>>>>> I get:
>>>>> [1] IDWeek Total  Fry    Smolt  FryEq  Year
>>>>> <0 rows> (or 0-length row.names)
>>> 
>>> The above is not an error message.  It says that there
>>> are no rows satisfying your criteria.  Note that Total==max(Total)
>>> returns a TRUE for each row in which the Total value
>>> equals the maximum Total value over all the years in
>>> the data.  Are you looking for the maximum value of Total
>>> in each year?
>>> 
>>>> tmp <- transform(fish, YearlyMaxTotal = ave(Total, Year, FUN=max))
>>>> subset(tmp, Total==YearlyMaxTotal)
>>>  IDWeek  Total    Fry  Smolt  FryEq Year YearlyMaxTotal
>>> 21    47 303259  34008 269248 491733 2012        303259
>>> 39    39 157260 156909    351 157506 2011        157260
>>>> subset(tmp, Total==YearlyMaxTotal & Year==2012)
>>>  IDWeek  Total  Fry  Smolt  FryEq Year YearlyMaxTotal
>>> 21    47 303259 34008 269248 491733 2012        303259
>>> 
>>> Bill Dunlap
>>> Spotfire, TIBCO Software
>>> wdunlap tibco.com
>>> 
>>> 
>>>> -Original Message-
>>>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
>>>> On Behalf
>>>> Of Felipe Carrillo
>>>> Sent: Sunday, December 02, 2012 10:47 AM
>>>> To: arun
>>>> Cc: R help
>>>> Subject: Re: [R] simple subset question
>>>> 
>>>> Works with the small dataset (2 years) but I get the error message with 
>>>> the whole
>>>> dataset (12 years of data). I am going to have
>>>> to check what's wrong with it...Thanks
>>>> 
>>>> Felipe D. Carrillo
>>>> Supervisory Fishery Biologist
>>>> Department of the Interior
>>>> US Fish & Wildlife Service
>>>> California, USA
>>>> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>>>> 
>>>> 
>>>> From: arun 
>>>>> To: Felipe Carrillo 
>>>>> Cc: R help ; R. Michael Weylandt
>>>> 
>>>>> Sent: Sunday, December 2, 2012 10:29 AM
>>>>> Subject: Re: [R] si

Re: [R] simple subset question

2012-12-02 Thread David Winsemius
The reason I suggested the alternative that I did was because your  
code could fail when the max(Total) value was not in the subset where  
Year==2012.


--
David
On Dec 2, 2012, at 11:34 AM, Felipe Carrillo wrote:



Using my whole dataset I get:
library(plyr)
ddply(winter,"Year",summarise,maxTotal=max(Total))

 fish <- structure(list(Year = 2002:2012, maxTotal = c(1464311L,  
1071051L,

714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L,
157260L, 303259L)), .Names = c("Year", "maxTotal"), row.names = c(NA,
-11L), class = "data.frame")

I only want to extract the max Total for 2012 and want the whole row  
like this:

 IDWeek  Total   Fry  Smolt  FryEq Year
21 47 303259 34008 269248 491733 2012

My whole dataset is too big to post it so thanks for your help and  
will try

to figure out why subset returns an empty row

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: William Dunlap 
To: Felipe Carrillo ; arun >

Cc: R help 
Sent: Sunday, December 2, 2012 11:00 AM
Subject: RE: [R] simple subset question


I am
still getting an error message

with :
  x <- subset(fish,Year==2012 & Total==max(Total));x
I get:
[1] IDWeek Total  FrySmolt  FryEq  Year
<0 rows> (or 0-length row.names)


The above is not an error message.  It says that there
are no rows satisfying your criteria.  Note that Total==max(Total)
returns a TRUE for each row in which the Total value
equals the maximum Total value over all the years in
the data.  Are you looking for the maximum value of Total
in each year?


tmp <- transform(fish, YearlyMaxTotal = ave(Total, Year, FUN=max))
subset(tmp, Total==YearlyMaxTotal)

  IDWeek  TotalFry  Smolt  FryEq Year YearlyMaxTotal
2147 303259  34008 269248 491733 2012303259
3939 157260 156909351 157506 2011157260

subset(tmp, Total==YearlyMaxTotal & Year==2012)

  IDWeek  Total  Fry  Smolt  FryEq Year YearlyMaxTotal
2147 303259 34008 269248 491733 2012303259

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
] On Behalf

Of Felipe Carrillo
Sent: Sunday, December 02, 2012 10:47 AM
To: arun
Cc: R help
Subject: Re: [R] simple subset question

Works with the small dataset (2 years) but I get the error message  
with the whole

dataset (12 years of data). I am going to have
to check what's wrong with it...Thanks

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: arun 

To: Felipe Carrillo 
Cc: R help ; R. Michael Weylandt



Sent: Sunday, December 2, 2012 10:29 AM
Subject: Re: [R] simple subset question

Hi,
I am getting this:
x<-subset(fish,Year==2012 & Total==max(Total))
 x
#   IDWeek  Total   Fry  Smolt  FryEq Year
#21 47 303259 34008 269248 491733 2012
A.K.




- Original Message -
From: Felipe Carrillo 
To: R. Michael Weylandt 
Cc: "r-help@r-project.org" 
Sent: Sunday, December 2, 2012 1:25 PM
Subject: Re: [R] simple subset question

Sorry, I was trying it to subset from a bigger dataset called  
'winter' and forgot to

change the variable names
when I asked the question. David W suggestion works but the  
strange part is that I am

still getting an error message

with :
  x <- subset(fish,Year==2012 & Total==max(Total));x
I get:
[1] IDWeek Total  FrySmolt  FryEq  Year
<0 rows> (or 0-length row.names)

I will start a fresh session to see if that helps...Thank you all

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: R. Michael Weylandt 

To: Felipe Carrillo 
Cc: "r-help@r-project.org" 
Sent: Sunday, December 2, 2012 9:42 AM
Subject: Re: [R] simple subset question

On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
 wrote:

  Hi,
Consider the small dataset below, I want to subset by two  
variables in
one line but it wont work...it works though if I subset  
separately. I have
to be missing something obvious that I did not realize before  
while using subset..


fish <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L,  
33L,

34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L,  
53015L,
91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L,  
303259L,

19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 

Re: [R] simple subset question

2012-12-02 Thread Felipe Carrillo
 
Using my whole dataset I get:
library(plyr)
ddply(winter,"Year",summarise,maxTotal=max(Total))
 
 fish <- structure(list(Year = 2002:2012, maxTotal = c(1464311L, 1071051L, 
714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L, 
157260L, 303259L)), .Names = c("Year", "maxTotal"), row.names = c(NA, 
-11L), class = "data.frame")
 
I only want to extract the max Total for 2012 and want the whole row like this:
 IDWeek  Total   Fry  Smolt  FryEq Year
21 47 303259 34008 269248 491733 2012
 
My whole dataset is too big to post it so thanks for your help and will try
to figure out why subset returns an empty row

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: William Dunlap 
>To: Felipe Carrillo ; arun  
>Cc: R help  
>Sent: Sunday, December 2, 2012 11:00 AM
>Subject: RE: [R] simple subset question
>
>> I am
>> still getting an error message
>> >with :
>> >  x <- subset(fish,Year==2012 & Total==max(Total));x
>> >I get:
>> >[1] IDWeek Total  Fry    Smolt  FryEq  Year
>> ><0 rows> (or 0-length row.names)
>
>The above is not an error message.  It says that there
>are no rows satisfying your criteria.  Note that Total==max(Total)
>returns a TRUE for each row in which the Total value
>equals the maximum Total value over all the years in
>the data.  Are you looking for the maximum value of Total
>in each year?
>
>> tmp <- transform(fish, YearlyMaxTotal = ave(Total, Year, FUN=max))
>> subset(tmp, Total==YearlyMaxTotal)
>  IDWeek  Total    Fry  Smolt  FryEq Year YearlyMaxTotal
>21    47 303259  34008 269248 491733 2012        303259
>39    39 157260 156909    351 157506 2011        157260
>> subset(tmp, Total==YearlyMaxTotal & Year==2012)
>  IDWeek  Total  Fry  Smolt  FryEq Year YearlyMaxTotal
>21    47 303259 34008 269248 491733 2012        303259
>
>Bill Dunlap
>Spotfire, TIBCO Software
>wdunlap tibco.com
>
>
>> -----Original Message-----
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
>> Behalf
>> Of Felipe Carrillo
>> Sent: Sunday, December 02, 2012 10:47 AM
>> To: arun
>> Cc: R help
>> Subject: Re: [R] simple subset question
>> 
>> Works with the small dataset (2 years) but I get the error message with the 
>> whole
>> dataset (12 years of data). I am going to have
>> to check what's wrong with it...Thanks
>> 
>> Felipe D. Carrillo
>> Supervisory Fishery Biologist
>> Department of the Interior
>> US Fish & Wildlife Service
>> California, USA
>> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>> 
>> 
>> From: arun 
>> >To: Felipe Carrillo 
>> >Cc: R help ; R. Michael Weylandt
>> 
>> >Sent: Sunday, December 2, 2012 10:29 AM
>> >Subject: Re: [R] simple subset question
>> >
>> >Hi,
>> >I am getting this:
>> >x<-subset(fish,Year==2012 & Total==max(Total))
>> > x
>> >#   IDWeek  Total   Fry  Smolt  FryEq Year
>> >#21 47 303259 34008 269248 491733 2012
>> >A.K.
>> >
>> >
>> >
>> >
>> >- Original Message -
>> >From: Felipe Carrillo 
>> >To: R. Michael Weylandt 
>> >Cc: "r-help@r-project.org" 
>> >Sent: Sunday, December 2, 2012 1:25 PM
>> >Subject: Re: [R] simple subset question
>> >
>> >Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
>> >forgot to
>> change the variable names
>> >when I asked the question. David W suggestion works but the strange part is 
>> >that I am
>> still getting an error message
>> >with :
>> >  x <- subset(fish,Year==2012 & Total==max(Total));x
>> >I get:
>> >[1] IDWeek Total  Fry    Smolt  FryEq  Year
>> ><0 rows> (or 0-length row.names)
>> >
>> >I will start a fresh session to see if that helps...Thank you all
>> >
>> >Felipe D. Carrillo
>> >Supervisory Fishery Biologist
>> >Department of the Interior
>> >US Fish & Wildlife Service
>> >California, USA
>> >http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>> >
>> >
>> >From: R. Michael Weylandt 
>> >>To: Felipe Carrillo 
>> >>Cc: "r-help@r-project.org" 
>> >>Sent: Sunday, December 2, 2012 9:42 AM
>> >>Subject: Re: [R] simple subset question
>> >>
>> >>On Sun, Dec 

Re: [R] simple subset question

2012-12-02 Thread William Dunlap
> I am
> still getting an error message
> >with :
> >  x <- subset(fish,Year==2012 & Total==max(Total));x
> >I get:
> >[1] IDWeek Total  FrySmolt  FryEq  Year
> ><0 rows> (or 0-length row.names)

The above is not an error message.  It says that there
are no rows satisfying your criteria.  Note that Total==max(Total)
returns a TRUE for each row in which the Total value
equals the maximum Total value over all the years in
the data.  Are you looking for the maximum value of Total
in each year?

> tmp <- transform(fish, YearlyMaxTotal = ave(Total, Year, FUN=max))
> subset(tmp, Total==YearlyMaxTotal)
   IDWeek  TotalFry  Smolt  FryEq Year YearlyMaxTotal
21 47 303259  34008 269248 491733 2012 303259
39 39 157260 156909351 157506 2011 157260
> subset(tmp, Total==YearlyMaxTotal & Year==2012)
   IDWeek  Total   Fry  Smolt  FryEq Year YearlyMaxTotal
21 47 303259 34008 269248 491733 2012 303259

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of Felipe Carrillo
> Sent: Sunday, December 02, 2012 10:47 AM
> To: arun
> Cc: R help
> Subject: Re: [R] simple subset question
> 
> Works with the small dataset (2 years) but I get the error message with the 
> whole
> dataset (12 years of data). I am going to have
> to check what's wrong with it...Thanks
> 
> Felipe D. Carrillo
> Supervisory Fishery Biologist
> Department of the Interior
> US Fish & Wildlife Service
> California, USA
> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
> 
> 
> From: arun 
> >To: Felipe Carrillo 
> >Cc: R help ; R. Michael Weylandt
> 
> >Sent: Sunday, December 2, 2012 10:29 AM
> >Subject: Re: [R] simple subset question
> >
> >Hi,
> >I am getting this:
> >x<-subset(fish,Year==2012 & Total==max(Total))
> > x
> >#   IDWeek  Total   Fry  Smolt  FryEq Year
> >#21 47 303259 34008 269248 491733 2012
> >A.K.
> >
> >
> >
> >
> >- Original Message -
> >From: Felipe Carrillo 
> >To: R. Michael Weylandt 
> >Cc: "r-help@r-project.org" 
> >Sent: Sunday, December 2, 2012 1:25 PM
> >Subject: Re: [R] simple subset question
> >
> >Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
> >forgot to
> change the variable names
> >when I asked the question. David W suggestion works but the strange part is 
> >that I am
> still getting an error message
> >with :
> >  x <- subset(fish,Year==2012 & Total==max(Total));x
> >I get:
> >[1] IDWeek Total  Fry    Smolt  FryEq  Year
> ><0 rows> (or 0-length row.names)
> >
> >I will start a fresh session to see if that helps...Thank you all
> >
> >Felipe D. Carrillo
> >Supervisory Fishery Biologist
> >Department of the Interior
> >US Fish & Wildlife Service
> >California, USA
> >http://www.fws.gov/redbluff/rbdd_jsmp.aspx
> >
> >
> >From: R. Michael Weylandt 
> >>To: Felipe Carrillo 
> >>Cc: "r-help@r-project.org" 
> >>Sent: Sunday, December 2, 2012 9:42 AM
> >>Subject: Re: [R] simple subset question
> >>
> >>On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
> >> wrote:
> >>>  Hi,
> >>> Consider the small dataset below, I want to subset by two variables in
> >>> one line but it wont work...it works though if I subset separately. I have
> >>> to be missing something obvious that I did not realize before while using 
> >>> subset..
> >>>
> >>> fish <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
> >>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> >>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> >>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> >>> 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
> >>> 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
> >>> 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
> >>> 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
> >>> 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
> >>> 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
> >>> 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
> >>> 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
> >&

Re: [R] simple subset question

2012-12-02 Thread R. Michael Weylandt
On Sun, Dec 2, 2012 at 6:46 PM, Felipe Carrillo
 wrote:
> Works with the small dataset (2 years) but I get the error message with the
> whole dataset (12 years of data). I am going to have
> to check what's wrong with it...Thanks

Off the cuff guess: there's a NA in Total so max(Total) is NA which
throws a wrench in `==`.

MW

__
R-help@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.


Re: [R] simple subset question

2012-12-02 Thread Felipe Carrillo
Works with the small dataset (2 years) but I get the error message with the 
whole dataset (12 years of data). I am going to have
to check what's wrong with it...Thanks

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: arun 
>To: Felipe Carrillo  
>Cc: R help ; R. Michael Weylandt 
> 
>Sent: Sunday, December 2, 2012 10:29 AM
>Subject: Re: [R] simple subset question
>
>Hi,
>I am getting this:
>x<-subset(fish,Year==2012 & Total==max(Total))
> x
>#   IDWeek  Total   Fry  Smolt  FryEq Year
>#21 47 303259 34008 269248 491733 2012
>A.K.
>
>
>
>
>- Original Message -
>From: Felipe Carrillo 
>To: R. Michael Weylandt 
>Cc: "r-help@r-project.org" 
>Sent: Sunday, December 2, 2012 1:25 PM
>Subject: Re: [R] simple subset question
>
>Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
>forgot to change the variable names
>when I asked the question. David W suggestion works but the strange part is 
>that I am still getting an error message
>with :
>  x <- subset(fish,Year==2012 & Total==max(Total));x
>I get:
>[1] IDWeek Total  Fry    Smolt  FryEq  Year  
><0 rows> (or 0-length row.names)
> 
>I will start a fresh session to see if that helps...Thank you all
>
>Felipe D. Carrillo
>Supervisory Fishery Biologist
>Department of the Interior
>US Fish & Wildlife Service
>California, USA
>http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>
>
>From: R. Michael Weylandt 
>>To: Felipe Carrillo  
>>Cc: "r-help@r-project.org"  
>>Sent: Sunday, December 2, 2012 9:42 AM
>>Subject: Re: [R] simple subset question
>>
>>On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
>> wrote:
>>>  Hi,
>>> Consider the small dataset below, I want to subset by two variables in
>>> one line but it wont work...it works though if I subset separately. I have
>>> to be missing something obvious that I did not realize before while using 
>>> subset..
>>>
>>> fish <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
>>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>>> 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
>>> 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
>>> 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
>>> 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
>>> 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
>>> 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
>>> 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
>>> 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
>>> 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
>>> 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
>>> 30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
>>> 1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
>>> 0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
>>> 23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
>>> 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
>>> 905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
>>> 31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
>>> 1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
>>> 94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
>>> 33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
>>> 13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
>>> 53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
>>> 22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
>>> 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
>>> 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
>>> 2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
>>> 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
>>> 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
>>> 2011L)), .Names = c("IDWeek", "Total", "Fry", "Smolt", "FryEq",
>>> "Year"), row.names = c(NA, 52L), class = "data.frame")
>>

Re: [R] simple subset question

2012-12-02 Thread Felipe Carrillo
Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
forgot to change the variable names
when I asked the question. David W suggestion works but the strange part is 
that I am still getting an error message
with :
  x <- subset(fish,Year==2012 & Total==max(Total));x
I get:
[1] IDWeek Total  Fry    Smolt  FryEq  Year  
<0 rows> (or 0-length row.names)
 
I will start a fresh session to see if that helps...Thank you all

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: R. Michael Weylandt 
>To: Felipe Carrillo  
>Cc: "r-help@r-project.org"  
>Sent: Sunday, December 2, 2012 9:42 AM
>Subject: Re: [R] simple subset question
>
>On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
> wrote:
>>  Hi,
>> Consider the small dataset below, I want to subset by two variables in
>> one line but it wont work...it works though if I subset separately. I have
>> to be missing something obvious that I did not realize before while using 
>> subset..
>>
>> fish <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
>> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
>> 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
>> 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
>> 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
>> 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
>> 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
>> 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
>> 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
>> 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
>> 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
>> 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
>> 30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
>> 1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
>> 0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
>> 23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
>> 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
>> 905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
>> 31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
>> 1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
>> 94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
>> 33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
>> 13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
>> 53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
>> 22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
>> 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
>> 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
>> 2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
>> 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
>> 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
>> 2011L)), .Names = c("IDWeek", "Total", "Fry", "Smolt", "FryEq",
>> "Year"), row.names = c(NA, 52L), class = "data.frame")
>> fish
>> #  Subset to get the max Total for 2012
>>  x <- subset(winter,Year==2012 & Total==max(Total));b  # How come one line 
>>doesn't work?
>
>Works fine for me if I change "winter" to fish here.
>
>subset(fish,Year==2012 & Total==max(Total))
>  IDWeek  Total  Fry  Smolt  FryEq Year
>21    47 303259 34008 269248 491733 2012
>
>>
>>  # It works if I subset the year first and then get the Total max from it
>>  xx <- subset(winter,Year==2012)
>> xxx <- subset(xx,Total==max(Total));xxx
>> xxx
>>
>> Felipe D. Carrillo
>> Supervisory Fishery Biologist
>> Department of the Interior
>> US Fish & Wildlife Service
>> California, USA
>> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>>
>>        [[alternative HTML version deleted]]
>>
>>
>> __
>> R-help@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.
>>
>
>
>
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] simple subset question

2012-12-02 Thread Gerrit Eichner

Hi, Felipe,

two typos? See below!

On Sun, 2 Dec 2012, Felipe Carrillo wrote:


 Hi,
Consider the small dataset below, I want to subset by two variables in
one line but it wont work...it works though if I subset separately. I have
to be missing something obvious that I did not realize before while using 
subset..

fish <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,



... [snip]



2011L)), .Names = c("IDWeek", "Total", "Fry", "Smolt", "FryEq",
"Year"), row.names = c(NA, 52L), class = "data.frame")
fish
#  Subset to get the max Total for 2012
  x <- subset(winter,Year==2012 & Total==max(Total));b  # How come one line 
doesn't work?


Don't you want *fish* instead of *winter* and *x* instead of *b*, as in

x <- subset(  fish,Year==2012 & Total==max(Total));x

?

 Hth  --  Gerrit


 
  # It works if I subset the year first and then get the Total max from it
  xx <- subset(winter,Year==2012) 
xxx <- subset(xx,Total==max(Total));xxx  
xxx
__
R-help@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.


Re: [R] simple subset question

2012-12-02 Thread R. Michael Weylandt
On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
 wrote:
>  Hi,
> Consider the small dataset below, I want to subset by two variables in
> one line but it wont work...it works though if I subset separately. I have
> to be missing something obvious that I did not realize before while using 
> subset..
>
> fish <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
> 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
> 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
> 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
> 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
> 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
> 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
> 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
> 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
> 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
> 30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
> 1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
> 0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
> 23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
> 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
> 905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
> 31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
> 1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
> 94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
> 33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
> 13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
> 53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
> 22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> 2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
> 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
> 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
> 2011L)), .Names = c("IDWeek", "Total", "Fry", "Smolt", "FryEq",
> "Year"), row.names = c(NA, 52L), class = "data.frame")
> fish
> #  Subset to get the max Total for 2012
>   x <- subset(winter,Year==2012 & Total==max(Total));b  # How come one line 
> doesn't work?

Works fine for me if I change "winter" to fish here.

subset(fish,Year==2012 & Total==max(Total))
   IDWeek  Total   Fry  Smolt  FryEq Year
21 47 303259 34008 269248 491733 2012

>
>   # It works if I subset the year first and then get the Total max from it
>   xx <- subset(winter,Year==2012)
> xxx <- subset(xx,Total==max(Total));xxx
> xxx
>
> Felipe D. Carrillo
> Supervisory Fishery Biologist
> Department of the Interior
> US Fish & Wildlife Service
> California, USA
> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>
> [[alternative HTML version deleted]]
>
>
> __
> R-help@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.
>

__
R-help@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.


Re: [R] simple subset question

2012-12-02 Thread David Winsemius


On Dec 2, 2012, at 9:21 AM, Felipe Carrillo wrote:


 Hi,
Consider the small dataset below, I want to subset by two variables in
one line but it wont work...it works though if I subset separately.  
I have
to be missing something obvious that I did not realize before while  
using subset..


fish <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L)), .Names = c("IDWeek", "Total", "Fry", "Smolt", "FryEq",
"Year"), row.names = c(NA, 52L), class = "data.frame")
fish
#  Subset to get the max Total for 2012
  x <- subset(winter,Year==2012 & Total==max(Total));b  # How come  
one line doesn't work?


  # It works if I subset the year first and then get the Total max  
from it

  xx <- subset(winter,Year==2012)
xxx <- subset(xx,Total==max(Total));xxx
xxx


Try instead either of these one step operations:
> xxx <- max( subset(fish, Year==2012 )$Total) ;xxx
[1] 303259
> xxx <- max( subset(fish, Year==2012 , Total) ) ;xxx
[1] 303259

--
David Winsemius, MD
Alameda, CA, USA

__
R-help@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.


Re: [R] simple subset question

2012-12-02 Thread Anthony Damico
shouldn't you just change b to x and winter to fish?  :)


On Sun, Dec 2, 2012 at 12:21 PM, Felipe Carrillo
wrote:

>  Hi,
> Consider the small dataset below, I want to subset by two variables in
> one line but it wont work...it works though if I subset separately. I have
> to be missing something obvious that I did not realize before while using
> subset..
>
> fish <- structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
> 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
> 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
> 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
> 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
> 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
> 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
> 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
> 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
> 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
> 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
> 30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
> 1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
> 0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
> 23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
> 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
> 905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
> 31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
> 1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
> 94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
> 33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
> 13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
> 53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
> 22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> 2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
> 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
> 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
> 2011L)), .Names = c("IDWeek", "Total", "Fry", "Smolt", "FryEq",
> "Year"), row.names = c(NA, 52L), class = "data.frame")
> fish
> #  Subset to get the max Total for 2012
>   x <- subset(winter,Year==2012 & Total==max(Total));b  # How come one
> line doesn't work?
>
>   # It works if I subset the year first and then get the Total max from it
>   xx <- subset(winter,Year==2012)
> xxx <- subset(xx,Total==max(Total));xxx
> xxx
>
> Felipe D. Carrillo
> Supervisory Fishery Biologist
> Department of the Interior
> US Fish & Wildlife Service
> California, USA
> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>
> [[alternative HTML version deleted]]
>
>
> __
> R-help@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.
>
>

[[alternative HTML version deleted]]

__
R-help@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.