Number of valid digits in the javer interface.

Asked 2 years ago, Updated 2 years ago, 39 views

[Question]
You are using javer interface (JRI) to obtain the results of R.
There is a difference between the number of digits returned by JRI and the number of digits returned by R's GUI, so I don't know where to specify the number of digits for JRI.
Please let me know.

[Event]
R GUI 1. Run getOption (digits) to verify that it is the default of 7.
2. Executed the command "t.test" to verify that t is -1.234567 (the number is temporary).
JRI
1. Executed the same command as GUI 1. on R in eval to verify that it is the default of 7.
2. If you run the same command as GUI 2. of R in EVAL, t will be -1.23456789012345 (the number is temporary).
✳ Even if you run Option(digits=1) on the veval, the results will be the same as in 2.

above.

情報Other information br
JRI-0.9.7.jar
spring boot 1.5.19
java 1.8

[Source Code]
The image is as follows.
Only the necessary parts are extracted.

~
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
~


public static void main(String[]args) {

    Engine engine = new Engine (new String[]{"--no-save"}, false, null);

    // dataframe creation
    engine.eval("dataaframe<-data.frame(\"group1\"=c(100,101,102,103,104,105,106,107,108,109,111,111,113,114,116,117,118,119,121,122,123,124,125,125,127,128,128,158,159,157,156,155);

    // Here you get 7 back.
    engine.eval("getOption(\"digits\");
    engine.eval("options(digits=5)";

    // Here you get a five.
    engine.eval("getOption(\"digits\");

    // ★ The number of digits in the acquisition result is different from when RGUI was executed.
    REXP result=engine.eval("t.test(dataaframe$group1,mu=150, alternative=\"less\", data=dataaframe")";
}

java r

2022-09-30 18:18

1 Answers

optionsHelp

digits:controls the number of digits to print when printing numeric values.

and so on.In short, options(digits) controls the number of digits displayed in a number.Only the display is , and internally, it has a valid decimal digit of about 15 digits.If you calculate with R, regardless of the options(digits) setting, you use all of these valid digits.

Since what JNI is getting is a number, not a display result, the options(digits) setting is completely irrelevant.

If you want to reduce the number of significant digits in the number itself, you will need to calculate it separately.


2022-09-30 18:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.