[R] simple subset question
Gerrit Eichner
Gerrit.Eichner at math.uni-giessen.de
Sun Dec 2 18:45:08 CET 2012
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
>
More information about the R-help
mailing list