0

I am creating KeyValue pair as below:

    Market <- c("ESA", "CLA", "GCA", "DXA")
    Market_ID <- c(11,13,14,17)
    MI_KV <- setNames(as.list(Market), Market_ID)
    MI<-13

When I do the following, I get the desired output:

    > MI_KV$`13`
    [1]"CLA"

But When I do the following, I get NULL value as output:

   > MI_KV$MI
   NULL

How do I retrieve the value using the above command as MI will be dynamic?

Prince Modi
  • 425
  • 1
  • 4
  • 16

1 Answers1

1

We can use [[ and make sure to convert the object to character

MI_KV[[as.character(MI)]]
#[1] "CLA"
akrun
  • 874,273
  • 37
  • 540
  • 662