I need to map an integer to an integer in R. In python this is the job of a dictionary
>>> a = { 4: 1, 5: 2, 6:3 }
>>> a[5]
2
but no such thing exists in R. A vector does not work:
a<- c(1,2,3)
> a
[1] 1 2 3
> names(a) <- c(5,6,7)
> a
5 6 7
1 2 3
> a[[5]]
Error in a[[5]] : subscript out of bounds
a list doesn't work either
> a<- list(1,2,3)
> a
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
> names(a) <- c(4, 5, 6)
> a
$`4`
[1] 1
$`5`
[1] 2
$`6`
[1] 3
> a[[6]]
Error in a[[6]] : subscript out of bounds