Reputation: 7351
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
Upvotes: 1
Views: 77
Reputation: 2716
names(a) is a character vector so you use the quotes
a['44']
44
"UK"
Upvotes: 1