R包hash用法

1,给一个hash赋值

h <- hash( keys=letters, values=1:26 )
h <- hash( letters, 1:26 )

2,取出一个哈希对

h[“a”]

3,取出某个键对应的值

h[[“a”]]

4,清空元素

clear(h)

5,删除这个哈希

rm(h)

6,循环赋值(也可以用于单独赋值)

h<-hash()
for (i in 1:7296) {
.set(h, keys = row.names(drug)[i], values = as.vector(drug[i,1]))
}
h.new<-h只是将h链接到了h.new, h.new<-copy(h)可以实现独立的复制

7,删除键值为a的元素

del(“a”,h)

8,has.key(“a”,h) 判断有没有键a, 返回TRUE或FALSE

9,is.hash(h) 判断是否为哈希

10,is.empty signature(x = “hash”): Test if no key-values are assigned

11,length signature(x = “hash”): Return number of key-value pairs from the hash

12,invert(h) 交换h的键值对

13,make.keys(key) Given an vector of any type, make.keys tries to coerce it into a character vector that can be used as a hash key. This is used internally by the hash package and should not be normally needed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值