Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

r get variable name that has maximum

I've searched online for a while now but not really finding answers to this specific question. maybe im not using the right key words... but if there's already a thread on this question, please direct me to it!

so let's say the data looks like this:

a = 3 b = 5

now i want to find out which one is larger, so i do:

max(a,b)

this will only return me the "5", but i want it to return "b" i tried using which() but it keep saying "which is not logical" i also tried deparse() but i get a string of "5"

thanks for any help in advance!

like image 226
alwaysaskingquestions Avatar asked Sep 18 '25 08:09

alwaysaskingquestions


1 Answers

thanks andrewelamb for a great start on the answer. i changed the code a bit to produce the right answer i was looking for:

`a = 3
 b = 5
 v_name = ["a","b"]
 v_name[which.max(c(a,b))]`

hope it helps anyone else who has this problem as well in the future

like image 53
alwaysaskingquestions Avatar answered Sep 23 '25 11:09

alwaysaskingquestions