[R] Data frame: how to create list of row max?
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. Thanks, Joh __ R-help@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.
Re: [R] Data frame: how to create list of row max?
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@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 __ R-help@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.
Re: [R] Data frame: how to create list of row max?
do.call(pmax, dataframe[,intensityindeces]) if I understand you aright. On Mon, 19 Feb 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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.
Re: [R] Data frame: how to create list of row max?
On Monday 19 February 2007 11:53, Prof Brian Ripley wrote: do.call(pmax, dataframe[,intensityindeces]) Thank you very much for your help! Any idea why do.call(pmax,list(na.rm=TRUE),dataframe[,intensityindeces]) would give me Error in if (quote) { : argument is not interpretable as logical In addition: Warning message: the condition has length 1 and only the first element will be used in: if (quote) { ? Thanks, Joh pgpgfKKtY5smH.pgp Description: PGP signature __ R-help@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.
Re: [R] Data frame: how to create list of row max?
On Mon, 19 Feb 2007, Johannes Graumann wrote: On Monday 19 February 2007 11:53, Prof Brian Ripley wrote: do.call(pmax, dataframe[,intensityindeces]) Thank you very much for your help! Any idea why do.call(pmax,list(na.rm=TRUE),dataframe[,intensityindeces]) You want something like do.call(pmax, c(dataframe[,intensityindeces], list(na.rm=TRUE))) See ?do.call would give me Error in if (quote) { : argument is not interpretable as logical In addition: Warning message: the condition has length 1 and only the first element will be used in: if (quote) { ? Thanks, Joh -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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.
Re: [R] Data frame: how to create list of row max?
Try do.call(pmax,c(dataframe[,intensityindices],na.rm=TRUE)) This is like the second example in the help page for do.call On 19/02/07, Johannes Graumann [EMAIL PROTECTED] wrote: On Monday 19 February 2007 11:53, Prof Brian Ripley wrote: do.call(pmax, dataframe[,intensityindeces]) Thank you very much for your help! Any idea why do.call(pmax,list(na.rm=TRUE),dataframe[,intensityindeces]) would give me Error in if (quote) { : argument is not interpretable as logical In addition: Warning message: the condition has length 1 and only the first element will be used in: if (quote) { ? Thanks, Joh __ R-help@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. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP __ R-help@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.
Re: [R] Data frame: how to create list of row max?
Thanks to you and Brian Ripley. Quite confusing all this ... Thanks again. Joh On Monday 19 February 2007 13:42, David Barron wrote: Try do.call(pmax,c(dataframe[,intensityindices],na.rm=TRUE)) This is like the second example in the help page for do.call On 19/02/07, Johannes Graumann [EMAIL PROTECTED] wrote: On Monday 19 February 2007 11:53, Prof Brian Ripley wrote: do.call(pmax, dataframe[,intensityindeces]) Thank you very much for your help! Any idea why do.call(pmax,list(na.rm=TRUE),dataframe[,intensityindeces]) would give me Error in if (quote) { : argument is not interpretable as logical In addition: Warning message: the condition has length 1 and only the first element will be used in: if (quote) { ? Thanks, Joh __ R-help@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. pgp4utFI3ZYyo.pgp Description: PGP signature __ R-help@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.