尝试用两个级别在R中创建散列索引。
为了避免for循环和复制操作,我编写了以下代码:
library(hash)
index.value.model <- hash(keys = 1:10, values = rep(list(list()),10 ))
new.obj <- hash(keys = 1:100, values = rep(index.value.model, 100) )rep中的错误(index.value.model,100):尝试复制'S4‘类型的对象
我该怎么做?
发布于 2018-05-04 10:31:30
您的问题是由于规范的rep(index.value.model, 100),因为index.value.model没有一个正确的格式。看起来是这样的:
<hash> containing 10 key-value pair(s).
1 : NULL
10 : NULL
2 : NULL
3 : NULL
4 : NULL
5 : NULL
6 : NULL
7 : NULL
8 : NULL
9 : NULL如果您想要一个具有两个级别的哈希表,请尝试以下代码:
hash(keys = 1:100, values = rep(c("1","2"), 50) )
<hash> containing 100 key-value pair(s).
1 : 1
10 : 2
100 : 2
11 : 1
12 : 2
13 : 1
...
96 : 2
97 : 1
98 : 2
99 : 1https://stackoverflow.com/questions/50172705
复制相似问题