1

Similar to this one on dictionary in R, but my index (or key) is integer. So I have a vector c(1,1,44,44) and a mapping (1 -> US, 44 -> UK) and how can I get a vector of (US, US, UK, UK)?

The normal named vector method doesn't work.

> a = c('US','UK')
> names(a) = c(1, 44)
> a[44]
<NA> 
  NA
Community
  • 1
  • 1
jf328
  • 6,841
  • 10
  • 58
  • 82

1 Answers1

1

names(a) is a character vector so you use the quotes

a['44']
  44 
"UK" 
Mouad_Seridi
  • 2,666
  • 15
  • 27