llewmills
llewmills

Reputation: 3568

R function returning boolean of which element in vector is maximum

I need a boolean that tells me whether an element of a vector is that vector's maximum. Should return something like this

vec <- c(3,4,1,5)

maxBoolFunct(vec)

[1] FALSE FALSE FALSE  TRUE

max() just tells me what the maximum value actually is and which.max simply gives me the position in the vector. I need a boolean.

Upvotes: 0

Views: 453

Answers (1)

evansrhonda
evansrhonda

Reputation: 191

You can use logical indexing.

> vec = c(3,4,1,5)
> vec == max(vec)
[1] FALSE FALSE FALSE  TRUE

Upvotes: 3

Related Questions