R与JAVA的混合编程
我这里将UJMP包中的Matrix类型转化为二维数组再转化为,一维数组,再转换为R中的矩阵,获取矩阵返回二维数组也有相应的描述
注意:在使用时一定要加载Rserve服务,如果不是R系统中的包,还需加载包名。
int genoRCnt = (int) geno.getRowCount(); int genoCCnt = (int) geno.getColumnCount(); int phenoRCnt = (int) pheno.getRowCount(); int phenoCCnt = (int) pheno.getColumnCount(); double[] genoArray = new double[genoCCnt * genoRCnt]; double[] phenoArray = new double[phenoRCnt * phenoCCnt]; long begin = System.currentTimeMillis(); {//Translate Matrix geno In Java To Matrix In R int k1 = 0; for (int i = 0; i < genoRCnt; i++) { for (int j = 0; j < genoCCnt; j++) { genoArray[k1++] = geno.getAsDouble(i, j); } } c.assign("genoR", genoArray); c.voidEval("GenoInR<-matrix(genoR," + genoRCnt + "," + genoCCnt + ",TRUE" + ")"); // REXP phenoY = c.eval("GenoInR"); // MatrixFactory.importFromArray(phenoY.asDoubleMatrix()).showGUI(); } {//Translate Matrix pheno In Java To Matrix In R int k2 = 0; for (int i = 0; i < phenoRCnt; i++) { for (int j = 0; j < phenoCCnt; j++) { phenoArray[k2++] = pheno.getAsDouble(i, j); } } c.assign("phenoR", phenoArray); c.voidEval("PhenoInR<-matrix(phenoR," + phenoRCnt + "," + phenoCCnt + ",TRUE" + ")"); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。