0

在此代码中,变量xx返回 0 而不是 20,不应该计算它并将其值保留在 eval 之间吗?

     String[] Rargs = {"--vanilla"};
     Rengine re = new Rengine(Rargs, false, null);

     if (!re.waitForR()) {
         System.out.println("Cannot load R");
         return;
     }

     re.eval("xx = 0");
     for (int i=0; i<20; i++) {
         re.eval("xx =  xx + 1");
     }

     int xx = (re.eval("xx")).asInt();
     System.out.println("xx="+xx);

这是结果:

xx=0
4

1 回答 1

0

这是答案,需要使用asDouble()

double xx = (re.eval("xx")).asDouble();
于 2015-01-19T15:51:21.167 回答