Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use logical indexing.

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading