[R] Finding the column with the maximum value by row

2012-07-17 Thread Christopher Desjardins
Hi, Let's say I have the following data: a=matrix(c(1,2,4,4,2,1,1,2,4),nrow=3,byrow=T) a [,1] [,2] [,3] [1,]124 [2,]421 [3,]124 What syntax should I use to get R to tell me the column that corresponds to the maximum value for each row? For my

Re: [R] Finding the column with the maximum value by row

2012-07-17 Thread R. Michael Weylandt
apply(a, 1, which.max) Apply the which.max() function to the matrix a row-wise (1) Michael On Tue, Jul 17, 2012 at 5:03 PM, Christopher Desjardins cddesjard...@gmail.com wrote: Hi, Let's say I have the following data: a=matrix(c(1,2,4,4,2,1,1,2,4),nrow=3,byrow=T) a [,1] [,2] [,3]

Re: [R] Finding the column with the maximum value by row

2012-07-17 Thread arun
Hi, Try, apply(a,1,which.max) [1] 3 1 3 A.K. - Original Message - From: Christopher Desjardins cddesjard...@gmail.com To: r-help@r-project.org Cc: Sent: Tuesday, July 17, 2012 6:03 PM Subject: [R] Finding the column with the maximum value by row Hi, Let's say I have the following

Re: [R] Finding the column with the maximum value by row

2012-07-17 Thread Guillaume Bal
Hi, You should be able to reach your goal using functions which and apply On 7/17/2012 3:03 PM, Christopher Desjardins wrote: Hi, Let's say I have the following data: a=matrix(c(1,2,4,4,2,1,1,2,4),nrow=3,byrow=T) a [,1] [,2] [,3] [1,]124 [2,]421 [3,]1