Message-ID: <Pine.SOC.4.64.1212021842270.138@solcom.hrz.uni-giessen.de>
Date: 2012-12-02T17:45:08Z
From: Gerrit Eichner
Subject: simple subset question
In-Reply-To: <1354468911.27346.YahooMailNeo@web126002.mail.ne1.yahoo.com>
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
>