I have a named vector:
v <- c("morning"=80, "noon"=20, "night"=40)
printing min(v)
gives
[1] 20
I want to get this instead:
noon
20
Is there a simple way?
v[which.min(v)]
will give you the output you listed. But if you just want the name, and not the value, then do names(v)[which.min(v)]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With