zoukankan      html  css  js  c++  java
  • 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" + ")");
            }
  • 相关阅读:
    静态代码块执行时机
    java中的命令
    JDBC
    final, finally, finalize
    面向对象
    线程中常用的一些方法
    线程中的yield()
    线程中的join()
    Thread对象 既传入了Runnable对象又重写了run()方法
    Python 绘制词云
  • 原文地址:https://www.cnblogs.com/yican/p/4370144.html
Copyright © 2011-2022 走看看