Logo Search packages:      
Sourcecode: rserve version File versions  Download package

double [][] org::rosuda::JRclient::REXP::asDoubleMatrix (  )  [inline]

returns the content of the REXP as a matrix of doubles (2D-array: m[rows][cols]). This is the same form as used by popular math packages for Java, such as JAMA. This means that following leads to desired results:
Matrix m=new Matrix(c.eval("matrix(c(1,2,3,4,5,6),2,3)").asDoubleMatrix());

2D array of doubles in the form double[rows][cols] or null if the contents is no 2-dimensional matrix of doubles

Definition at line 537 of file REXP.java.

References asDoubleArray(), asIntArray(), asList(), attr, org::rosuda::JRclient::RList::getHead(), Xt, XT_ARRAY_DOUBLE, XT_ARRAY_INT, and XT_LIST.

Referenced by asMatrix().

        if (Xt!=XT_ARRAY_DOUBLE || attr==null || attr.Xt!=XT_LIST) return null;
        REXP dim=attr.asList().getHead();
        if (dim==null || dim.Xt!=XT_ARRAY_INT) return null; // we need dimension attr
        int[] ds=dim.asIntArray();
        if (ds==null || ds.length!=2) return null; // matrix must be 2-dimensional
        int m=ds[0], n=ds[1];
        double[][] r=new double[m][n];
        double[] ct=asDoubleArray();
        if (ct==null) return null;
        // R stores matrices as matrix(c(1,2,3,4),2,2) = col1:(1,2), col2:(3,4)
        // we need to copy everything, since we create 2d array from 1d array
        int i=0,k=0;
        while (i<n) {
            int j=0;
            while (j<m) {
        return r;

Generated by  Doxygen 1.6.0   Back to index