I am using Twitter anomaly detection algorithm in my project. To do this, I use the Rserve library to run R code in my Java application.
My Java code is:
RConnection connection = new RConnection();
connection.voidEval("library(AnomalyDetection)");
connection.eval("res <- AnomalyDetectionTs(data.frame(/*list of timestamps*/,/*list of values*/), direction='both', plot=FALSE, longterm=TRUE)");
And, as a result, I got this conclusion:
$anoms
timestamp anoms
1 1980-09-25 16:05:00 21.3510
2 1980-09-29 06:40:00 193.1036
3 1980-09-29 21:44:00 148.1740
To get the results, I use this not a pleasant solution:
connection.eval("write.csv(res[['anoms']],file='anom.csv')");
Then I will open this file in Java and analyze the results.
So how to get output in Java using the Rserve features for the data.frame structure?
source
share