1
Suppose I have the following variables:
x = 2
y = 3
z = 5
And turn them into a vector:
vetor = c(x,y,z)
I thought I’d use the function max
:
max(vetor)
[1] 5
But if I use the function max
returns a number to me, and I would actually like to know what the variable name is between x
, y
and z
is the largest, in which case the variable z
.
How can I know which is the largest variable of a vector in R?
Maybe
which.max
. But if you want the name, then the vector has to be a vector with names, a named vector. To create the vector will besetNames(vetor, c('x','y','z'))
.– Rui Barradas