[R] Finding the column with the maximum value by row
guillaume.bal.pro at gmail.com
Wed Jul 18 00:40:30 CEST 2012
You should be able to reach your goal using functions "which" and "apply"
On 7/17/2012 3:03 PM, Christopher Desjardins wrote:
> Let's say I have the following data:
> [,1] [,2] [,3]
> [1,] 1 2 4
> [2,] 4 2 1
> [3,] 1 2 4
> What syntax should I use to get R to tell me the column that corresponds to
> the maximum value for each row?
> For my example, I would like to get a vector that says 3, 1, 3 because the
> maximum value for row 1 is in column 3, the maximum value for row 2 is in
> column 1, and the maximum value for row 3 is in column 3.
> Does that make sense?
> Please cc me if you reply!
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help