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.

Reply via email to