Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用rJava在R中获取hashmap_Java_R - Fatal编程技术网

使用rJava在R中获取hashmap

使用rJava在R中获取hashmap,java,r,Java,R,我有一个带有数值的普通hashmap,希望检索它的内容,最好是在一个列表中(但这是可以解决的) 可以这样做吗?我自己从来没有这样做过,但是有一个使用with函数创建和使用HashMap的示例: HashMap <- J("java.util.HashMap") with( HashMap, new( SimpleEntry, "key", "value" ) ) with( HashMap, SimpleEntry ) HashMap试试这个: library(rJava) .jinit

我有一个带有数值的普通hashmap,希望检索它的内容,最好是在一个列表中(但这是可以解决的)


可以这样做吗?

我自己从来没有这样做过,但是有一个使用
with
函数创建和使用HashMap的示例:

HashMap <- J("java.util.HashMap")
with( HashMap, new( SimpleEntry, "key", "value" ) )
with( HashMap, SimpleEntry )
HashMap试试这个:

library(rJava)
.jinit()
# create a hash map
hm<-.jnew("java/util/HashMap")
# using jrcall instead of jcall, since jrcall uses reflection to get types 
.jrcall(hm,"put","one", "1")
.jrcall(hm,"put","two","2")
.jrcall(hm,"put","three", "3")

# convert to R list
keySet<-.jrcall(hm,"keySet")
an_iter<-.jrcall(keySet,"iterator")
aList <- list()
while(.jrcall(an_iter,"hasNext")){
  key <- .jrcall(an_iter,"next");
  aList[[key]] <- .jrcall(hm,"get",key)
}
库(rJava)
.jinit()
#创建哈希映射

谢谢谢恩。如果rJava有一些相反方向的例子,那将非常有用。谢谢。jcall在迭代器上对我不起作用,但它可以工作。伟大的