tom soyer
2006-Oct-21 15:29 UTC
[R] how do I find the row index number, or row name, of a given value in a vector?
Hi, I noticed that max(x) returns the maximum value of a vector, but the function doesn't give the user the option of retrieving the row index number instead. If I used max(x) to find the maximum value of vector x, then is there a function I can use to find the index number, or row name, of the maximum value? Thanks, Tom [[alternative HTML version deleted]]
John Kane
2006-Oct-21 16:03 UTC
[R] how do I find the row index number, or row name, of a given value in a vector?
--- tom soyer <tom.soyer at gmail.com> wrote:> Hi, > > I noticed that max(x) returns the maximum value of a > vector, but the > function doesn't give the user the option of > retrieving the row index number > instead. If I used max(x) to find the maximum value > of vector x, then is > there a function I can use to find the index number, > or row name, of the > maximum value? > > Thanks, > > Tom?which Is this what you want to do? xx <- c(1,2,3,4,9,6,7,5) bb <- max(xx) bb which(xx==bb)
Gabor Grothendieck
2006-Oct-21 16:09 UTC
[R] how do I find the row index number, or row name, of a given value in a vector?
?which.max On 10/21/06, tom soyer <tom.soyer at gmail.com> wrote:> Hi, > > I noticed that max(x) returns the maximum value of a vector, but the > function doesn't give the user the option of retrieving the row index number > instead. If I used max(x) to find the maximum value of vector x, then is > there a function I can use to find the index number, or row name, of the > maximum value? > > Thanks, > > Tom > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
Possibly Parallel Threads
- Retrieving matrix column and row names by index value
- re order vector in order given by another vector
- Identifying common prefixes from a vector of words, and delete those prefixes
- finding index of maximum value in vector
- Compare by row and insert previous row value (Or non Time Series Lag)