开发者

Add values to exsisting of a hash

开发者 https://www.devze.com 2023-04-07 03:08 出处:网络
how can on开发者_开发问答e insert additional values to an exsisting key of a hash in R. h=hash()

how can on开发者_开发问答e insert additional values to an exsisting key of a hash in R.

h=hash()
h[key1] = "value1"
. ???
h[key1] = exsisting values + "value2" = c(values(h),"value2")

??


First of all it may be useful to indicate why you want to use hash in the first place. Standard R contains a dataformat list which is also a key - value store. Unless there is a very specific need to use a different system, the system with list is well documented and has many useful functions like lapply which may not exist for your package.

You seem to want to create what is called a multimap in C++. There is no need to use hash for that, you can do it by nesting lists Eg:

h<-list()
h[['key1']]<-list("value1")
h[['key1']]<-list(unlist(h[['key1']]),'value2')
str(h)
List of 1
 $ key1:List of 2
  ..$ : chr "value1"
  ..$ : chr "value2"

If your values have the same datatype you don't even need the nested list:

h<-list()
h[['key1']]<-"value1"
h[['key1']]<-c(h[['key1']],'value2')
str(h)
List of 1
 $ key1: chr [1:2] "value1" "value2"
0

精彩评论

暂无评论...
验证码 换一张
取 消