If I have a list of interger, and I gave them string names, how do i get the name based on the value?
Is that possible?
Thanks
If I have a list of interger, and I gave them string names, how do i get the name based on the value?
Is that possible?
Thanks
 
    
    match with names works:
x <- list(a=2L,b=3L)
names(x)[match(2L,x)]
# [1] "a"
This also works if x is not actually a list, but a vector: x <- c(a=2L,b=3L).
If the value is not unique, it selects the first match:
x <- list(a=2L,b=3L,d=2L)
names(x)[match(2L,x)] # still "a"
