[R] hwo can i get a vector that...
dear all, how can i get a vector that shows the number of the column of matrix that contains the maximum of the row ?? can´t believe in need a loop for this... i have a 100 x 3 matrix and want to get a 100 x 1 vector with values 1,2,3 . there must be a simple solution. i just cannot find it. i think am searching on the wrong end. thx for help in advance. m. __ 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] hwo can i get a vector that...
dear all, how can i get a vector that shows the number of the column of matrix that contains the maximum of the row ?? can´t believe in need a loop for this... i have a 100 x 3 matrix and want to get a 100 x 1 vector with values 1,2,3 . there must be a simple solution. i just cannot find it. i think am searching on the wrong end. thx for help in advance. m. EDIT: ok, i know the following by now :) apply(for18[,-1], 1, max, na.rm=T) but this doesn´t get me the number of the column - which is what i need... [[alternative HTML version deleted]] __ 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] hwo can i get a vector that...
?apply ?which.max m - matrix(rnorm(12),nrow=4) m apply(m,1,which.max) Petr bunny , lautloscrew.com napsal(a): dear all, how can i get a vector that shows the number of the column of matrix that contains the maximum of the row ?? can´t believe in need a loop for this... i have a 100 x 3 matrix and want to get a 100 x 1 vector with values 1,2,3 . there must be a simple solution. i just cannot find it. i think am searching on the wrong end. thx for help in advance. m. __ 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. -- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic __ 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] hwo can i get a vector that...
apply(yourMatrix,1,which.max) Bert Gunter Nonclinical Statistics 7-7374 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of bunny , lautloscrew.com Sent: Wednesday, March 07, 2007 2:12 PM To: r-help@stat.math.ethz.ch Subject: [R] hwo can i get a vector that... dear all, how can i get a vector that shows the number of the column of matrix that contains the maximum of the row ?? can´t believe in need a loop for this... i have a 100 x 3 matrix and want to get a 100 x 1 vector with values 1,2,3 . there must be a simple solution. i just cannot find it. i think am searching on the wrong end. thx for help in advance. m. __ 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. __ 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] hwo can i get a vector that...
can´t believe in need a loop for this... No, you don't ;) want to get a 100 x 1 vector Has each row unique values? If yes: mat - matrix(rnorm(300),nr=100) vet - apply(mat,1,function(x) {return(which(x==max(x)))}) scionforbai __ 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] hwo can i get a vector that...
Check out which.max Peter Alspach -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of bunny , lautloscrew.com Sent: Thursday, 8 March 2007 11:20 a.m. To: R-help@stat.math.ethz.ch Subject: Re: [R] hwo can i get a vector that... dear all, how can i get a vector that shows the number of the column of matrix that contains the maximum of the row ?? can´t believe in need a loop for this... i have a 100 x 3 matrix and want to get a 100 x 1 vector with values 1,2,3 . there must be a simple solution. i just cannot find it. i think am searching on the wrong end. thx for help in advance. m. EDIT: ok, i know the following by now :) apply(for18[,-1], 1, max, na.rm=T) but this doesn´t get me the number of the column - which is what i need... [[alternative HTML version deleted]] __ The contents of this e-mail are privileged and/or confidenti...{{dropped}} __ 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] hwo can i get a vector that...
___ max.col sounds like what you're after. -- Hong Ooi Senior Research Analyst, IAG Limited 388 George St, Sydney NSW 2000 +61 (2) 9292 1566 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of bunny , lautloscrew.com Sent: Thursday, 8 March 2007 9:12 AM To: r-help@stat.math.ethz.ch Subject: [R] hwo can i get a vector that... dear all, how can i get a vector that shows the number of the column of matrix that contains the maximum of the row ?? can´t believe in need a loop for this... i have a 100 x 3 matrix and want to get a 100 x 1 vector with values 1,2,3 . there must be a simple solution. i just cannot find it. i think am searching on the wrong end. thx for help in advance. m. __ 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. ___ The information transmitted in this message and its attachme...{{dropped}} __ 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.