R java
来源:互联网 发布:linux开机挂载分区 编辑:程序博客网 时间:2024/06/08 15:49
Rcaller 2.0
java 调用R
sudo apt-get install r-base 此时/usr/bin/Rscript生效
下载http://code.google.com/p/rcaller/ jar 加入到classpath
打开shell ,输入R,运行R
输入:install.packages("Runiversal")
选北京失败,选加拿大。
安装完毕
执行java代码
try {
/*
* Creating Java's random number generator
*/
Random random = new Random();
/*
* Creating RCaller
*/
RCaller caller = new RCaller();
RCode code = new RCode();
/*
* Full path of the Rscript. Rscript is an executable file shipped with R.
* It is something like C:\\Program File\\R\\bin.... in Windows
*/
caller.setRscriptExecutable("/usr/bin/Rscript");
/*
* We are creating a random data from a normal distribution
* with zero mean and unit variance with size of 100
*/
double[] data = new double[100];
for (int i = 0; i < data.length; i++) {
data[i] = random.nextGaussian();
}
/*
* We are transferring the double array to R
*/
code.addDoubleArray("x", data);
/*
* Adding R Code
*/
code.addRCode("my.mean<-mean(x)");
code.addRCode("my.var<-var(x)");
code.addRCode("my.sd<-sd(x)");
code.addRCode("my.min<-min(x)");
code.addRCode("my.max<-max(x)");
code.addRCode("my.standardized<-scale(x)");
/*
* Combining all of them in a single list() object
*/
code.addRCode(
"my.all<-list(mean=my.mean, variance=my.var, sd=my.sd, min=my.min, max=my.max, std=my.standardized)");
/*
* We want to handle the list 'my.all'
*/
caller.setRCode(code);
caller.runAndReturnResult("my.all");
double[] results;
/*
* Retrieving the 'mean' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("mean");
System.out.println("Mean is " + results[0]);
/*
* Retrieving the 'variance' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("variance");
System.out.println("Variance is " + results[0]);
/*
* Retrieving the 'sd' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("sd");
System.out.println("Standard deviation is " + results[0]);
/*
* Retrieving the 'min' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("min");
System.out.println("Minimum is " + results[0]);
/*
* Retrieving the 'max' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("max");
System.out.println("Maximum is " + results[0]);
/*
* Retrieving the 'std' element of list 'my.all'
*/
results = caller.getParser().getAsDoubleArray("std");
/*
* Now we are retrieving the standardized form of vector x
*/
System.out.println("Standardized x is ");
for (int i = 0; i < results.length; i++) {
System.out.print(results[i] + ", ");
}
} catch (Exception e) {
System.out.println(e.toString());
}
http://code.google.com/p/rcaller/
2.4 JGR:java GUI for R——http://www.rforge.net/JGR/ >>>以Java 为主的同学们, 作图可以考虑 JGR。这个还不错!
JGR (speak ‘Jaguar’) is a universal and unified Graphical User Interface for R (it actually abbreviates Java Gui for R).
- R java
- R.java
- 丢失R.java文件
- JAVA Properties R/W
- JAVA notebook-by R
- 找不到R.java错误
- java /n /r /t
- R.java文件生成
- 找不到R.java 解决方法
- java /n /r /t
- Netbeans Android R.java
- android的R.java
- java /n /r /t
- 找不到R.java
- R.java不存在
- R.java常见问题解决方案
- java中调用R
- android R.java
- (转)批处理文件(*.bat和*.cmd)语法
- CentOS 6安装JDK及系统配置
- 广义表的实现(用类实现,包含构造函数,析构函数,遍历函数等)
- Ural-1020. Rope(简单计算几何)
- 如何修复Linux无法正常启动故障
- R java
- IE设置解决拒绝第三方写入cookies的设置方式
- 网页中插入音乐连续播放
- Struts2的输入校验(2):重写validate方法(方法二)
- 一步一步写STL:多级空间配置器(上)
- linux iostat命令输出简要说明
- shell中引用(反斜杠、单引号和双引号)
- 迄今见过最好的职业规划文章
- c++代码检测