我正在从 R 脚本中检索值(使用 Renjin 库),然后尝试在 java 中操作它们。R 脚本返回一个 ListVector,如下所示:
c(1L, 2L, 3L, 4L, 5L...10 elements total)
c(0.70836348202446, 3.27419352963856, 4.08477502998281, 4.11959291310495, 4.64797692435211,... 10 elements total)
c(10.88276411602949, 11.01414766445697, 14.22416580313999, 14.40880862158516, 15.64782262321588,... 10 elements total)
我希望能够从每个 Vector 中获取特定元素,因此在第一个实验中,我希望能够进行迭代,以便打印出所有元素。
为此,我正在做
ListVector exp = (ListVector) engine.eval(new java.io.FileReader("/Users/sebastianzeki/Desktop/script.R"));
java.util.Iterator<SEXP> itr = exp.iterator();
System.out.println("Iterating through Vector elements...");
while(itr.hasNext()){
java.util.Vector<SEXP> v=new Vector<SEXP>();
v.add(itr.next());
java.util.Iterator<SEXP> itr2 = v.iterator();
while(itr2.hasNext()){
System.out.println("My Elements"+itr2.next());
}
}
然而,这只是分别打印出每个向量,所以我最终得到
My Elementsc(1L, 2L, 3L, 4L, 5L...10 elements total)
My Elementsc(0.70836348202446, 3.27419352963856, 4.08477502998281, 4.11959291310495, 4.64797692435211,... 10 elements total)
My Elementsc(10.88276411602949, 11.01414766445697, 14.22416580313999, 14.40880862158516, 15.64782262321588,... 10 elements total)