I'm writing an expression that requires searching a vector according to 
group. As an example, I want to find the maximum value in each of 5 
groups.


group=rep(1:5, each=5)                          # create grouping variable 
 
variable=rnorm(25)                              # generate data

d <- data.frame(group,variable)                         # make data frame

max(d$variable[d$group])                        # try expression that 
doesn't work

I'm expecting a vector containing the maximum variable value, per group. 
What am I doing wrong? I know I can use aggregate, tapply, etc. but that 
seems awkward and bulky, is there a simpler way?


Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
 
        [[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.

Reply via email to