0 votes
1 view
ago in R Programming by (32.1k points)

Here is my code:

H = hash()

H[["numbers"]] = c(1,2,3)

H[["alpha"]] = c("x","y","z")

H[["animals"]] = c("cat","dog")

Now from the above I want to get "animals" using "cat". Basically I want to get the key of the hash, based on the value.

1 Answer

0 votes
ago by (70.8k points)

For achieving your goal, you can use hash::invert in R programming, refer to the following code:


[1] "animals"

And the above code will also works for multiple hashes with the same value.

H[["mammals"]] = c("cat","dog","human")


[1] "animals" "mammals"

Welcome to Intellipaat Community. Get your technical queries answered by top developers !