How to use the value of a variable as key in an R-environment?

后端 未结 1 1774
长发绾君心
长发绾君心 2020-12-25 14:17

In R programming language I want to use a hash table.

How do I use the value of a variable as the key for the environment?

For example:

map &         


        
相关标签:
1条回答
  • 2020-12-25 14:26

    As it says in ?"$":

     Both ‘[[’ and ‘$’ select a single element of the list.  The main
     difference is that ‘$’ does not allow computed indices, whereas
     ‘[[’ does.  ‘x$name’ is equivalent to ‘x[["name", exact =
     FALSE]]’.  Also, the partial matching behavior of ‘[[’ can be
     controlled using the ‘exact’ argument.
    

    So you want:

    map[[key]] <- 4
    > print(ls(map))
    [1] "ffffd" "key"
    > map[[key]]
    [1] 4
    
    0 讨论(0)
提交回复
热议问题