# [R] calling java from R and using java time series double precision array

Hurr hill0093 at umn.edu
Wed Mar 28 00:35:17 CEST 2012

```I solved some of my problems, but the one that remains is
that reading the two-dimensional arrays into R transposes the matrix.
The arrays I want to read are unequal interval time multi series with
the first column being the times which are converted in java from
calendar CnYrMoDaHrMnScDCMQ or CnYrMoDa and between to linear.
What R programs do I use to plot and analyse this kind of time series?
How can I prevent transpose.
THIS IS THE JAVA CODE:
public class Transf2R {
Transf2R transf2R;
public static void main(String[]args) {
Transf2R transf2R=new Transf2R(); transf2R.transf2R=transf2R;
transf2R.transf2R.main2();
}
public static void main2() { double[][]arRet=arReturnMethod();
for(int i=0;i<9;i++) { for(int
j=0;j<3;j++)System.out.print((int)con2Arr[i][j]+","); System.out.println();
}
for(int i=0;i<9;i++) { for(int
j=0;j<3;j++)System.out.print((int)arRet[i][j]+","); System.out.println(); }
}
public final static double con0dbl=10001;
public final static double[]con1Vec=new double[] {
10001,10002,10003,10004,10005,10006 };
public final static double[][]con2Arr=new double[][] {
{ 10001,10002,10003 },{ 20001,20002,20003 },{ 30001,30002,30003 },{
40001,40002,40003 }
,{ 50001,50002,50003 },{ 60001,60002,60003 },{ 70001,70002,70003 },{
80001,80002,80003 }
,{ 90001,90002,90003 }
};
public final static double[][]arReturnMethod() {
double[][]retArr=new double[9][3]; for(int i=0;i<9;i++)for(int
j=0;j<3;j++)retArr[i][j]=(i+1)*1000+j+1; return(retArr);
}
public final static double[][]dbl2DimArRet4R(double[][]dbl2DimAr4R) {
return(dbl2DimAr4R); }
public final static double[]dbl1DimVcRet4R(double[]dbl1DimVc4R) {
return(dbl1DimVc4R); }
public final static double dblRet4R(double dbl4R) { return(dbl4R); }
public final static double dblNum4R=Math.PI;
}
WHICH PRODUCES THIS UPON RUNNING MAIN():
10001,10002,10003,
20001,20002,20003,
30001,30002,30003,
40001,40002,40003,
50001,50002,50003,
60001,60002,60003,
70001,70002,70003,
80001,80002,80003,
90001,90002,90003,
1001,1002,1003,
2001,2002,2003,
3001,3002,3003,
4001,4002,4003,
5001,5002,5003,
6001,6002,6003,
7001,7002,7003,
8001,8002,8003,
9001,9002,9003,
I FINALLY FIGURED OUT SOME R CODE THAT DEMONSTRATES WHAT I WANT TO DO:
> .jinit()       # starts JVM
[1] 0
> print(.jclassPath())
[1] "C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.13\\rJava\\java"
> trnsfer2R <- .jnew("Transf2R") # creates link to java class
> arj9x3Ret <-
> sapply(.jcall(trnsfer2R,returnSig="[[D","arReturnMethod"),.jevalArray)
> print(arj9x3Ret) # note: row and column indices get interchanged
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 1001 2001 3001 4001 5001 6001 7001 8001 9001
[2,] 1002 2002 3002 4002 5002 6002 7002 8002 9002
[3,] 1003 2003 3003 4003 5003 6003 7003 8003 9003
> dblNum <- .jcall(trnsfer2R,returnSig="D","dblRet4R",trnsfer2R\$dblNum4R)
> print(dblNum,digits=20)
[1] 3.141592653589793116
> conn1Vec <-
> .jcall(trnsfer2R,returnSig="[D","dbl1DimVcRet4R",trnsfer2R\$con1Vec) #
> con1Vec is java one dim array of double precision constants
> print(conn1Vec)
[1] 10001 10002 10003 10004 10005 10006
> conn2Arr <-
> sapply(.jcall(trnsfer2R,returnSig="[[D","dbl2DimArRet4R",.jfield(trnsfer2R,
> "[[D", "con2Arr", convert=F)),.jevalArray)
> print(conn2Arr)
[,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9]
[1,] 10001 20001 30001 40001 50001 60001 70001 80001 90001
[2,] 10002 20002 30002 40002 50002 60002 70002 80002 90002
[3,] 10003 20003 30003 40003 50003 60003 70003 80003 90003
>
BUT THE TWO-DIMENSIONAL ARRAYS SEEM TO BE TRANSPOSED.

--
View this message in context: http://r.789695.n4.nabble.com/calling-java-from-R-and-using-java-time-series-double-precision-array-tp4494581p4510410.html
Sent from the R help mailing list archive at Nabble.com.

```