O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieving an array from R

The following steps help in retrieving an array from R:

  • Open the Java program, SimpleRservStat.java:
    • We instantiate a new RConnection object
    • We assign a Java array of doubles to an R variable
    • We calculate the mean of this array in R and print it in Java
    • We then calculate the range, and since range is an array, we invoke the asDoubles() method on the REXP object that is returned from the eval method
    • We then print the array of doubles after converting it into a string:
      • Execute the following Java code command line from the javasamples directory; be sure to pass your own R working directory in place of the last part of the command:
java -cp ..:../lib/* javasamples.SimpleRservStat /Users/sv/book/Chapter11 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required