在Eclipse中,json将数据从数据帧R映射到Java类
我在R ed中有一个数据帧,我在一个带有JRI库的java类中阅读它。我必须将数据框中包含的数据映射到java类中。我曾想过在json对象中转换数据帧并构建他们的POJO,但我需要帮助。有人能帮我吗?我为Web开发人员使用Eclipse Java EE IDE(版本:Luna Service Release 2(4.4.2))。谢谢
这是我的R脚本,名为“Rmongo.R:
library(rJava)
library(RMongo)
mongo <- mongoDbConnect("DBunical")
dbShowCollections(mongo)
results <- dbGetQuery(mongo, "Veicolo", '{}', 0, 3)
View(results)
结果是我的数据框架
这是我的java类:
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
public class rmongo {
public static void main(String[] args) {
System.out.println("Creating Rengine (with arguments)");
String[] Rargs = {"--vanilla"};
Rengine re = new Rengine(Rargs, false, null);
System.out.println("Rengine created, waiting for R");
// the engine creates R is a new thread, so we should wait until it's
// ready
if (!re.waitForR()) {
System.out.println("Cannot load R");
return;
}
System.out.println(re.eval(".libPaths(\"C:/Users/Stefania/Documents/R/win- library/3.2\")"));
System.out.println(re.eval(".libPaths()"));
re.eval("source(\"C:\\\\Rmongo.R\")");
}
}
共 (0) 个答案