[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.
情報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")";
}
options
Help
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.
601 GDB gets version error when attempting to debug with the Presense SDK (IDE)
891 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
611 Uncaught (inpromise) Error on Electron: An object could not be cloned
568 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.