[R] Data frame: how to create list of row max?

Chuck Cleland ccleland at optonline.net
Mon Feb 19 11:51:28 CET 2007


Johannes Graumann wrote:
> Dear all,
> 
> Can anyone please shed some light onto how to do this?
> 
> This will give me all "intensity" columsn in my data frame:
> intensityindeces <- grep("^Intensity",names(dataframe),value=TRUE)
> 
> This will give me the maximum intensity for the first row:
> intensityone <- max(dataframe[1,intensityindeces])
> 
> What I'm now looking for is how to dfo this for the whole data frame. Should
> yield a list of maximum intensities of all rows.
> Can't figure it out ... please nudge me where I need to go.

  If you want the values themselves:

apply(dataframe[,intensityindeces], 1, max)

  If you want the column in which the max appears:

apply(dataframe[,intensityindeces], 1, which.max)

?apply

> Thanks, Joh
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list