1
Example:
a=c(10,9,8,7)
b<-max(a)
a[b]
I need to know in which position b is located in vector a, R must return 1 (which is the answer)
1
Example:
a=c(10,9,8,7)
b<-max(a)
a[b]
I need to know in which position b is located in vector a, R must return 1 (which is the answer)
4
Take a look at the function which()
:
a=c(10,9,8,7)
b<-max(a)
a[b]
which(a == b)
# [1] 1
Other options is the function match()
:
match(b, a)
# [1] 1
4
Another way to solve is with the function which.max
:
a=c(10,9,8,7)
which.max(a)
[1] 1
Browser other questions tagged r
You are not signed in. Login or sign up in order to post.
Thank you very much, I am in the middle of a gigantic code for a job and did not know of this basic command! Grateful!
– Magliari