Retrieve result from R in C#

三世轮回 提交于 2019-12-14 02:56:26

问题


I used R.NET to perform Change Point Detection as following

REngine.SetEnvironmentVariables();
REngine engine = REngine.GetInstance();
double[] data = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
NumericVector vector = engine.CreateNumericVector(data);
engine.Evaluate("library(changepoint)");
engine.SetSymbol("values", vector);
engine.Evaluate("values.ts = ts(values, frequency = 12, start = c(2017, 1))");
engine.Evaluate("chpoints = cpt.mean(values.ts, method=\"BinSeg\")");
var result = engine.GetSymbol("chpoints");
engine.Dispose();

The Type of result is shown as RDotNet.SymbolicExpression and class of chpoints on RGui is shown as cpt

> class(chpoints)
[1] "cpt" 
attr(,"package") 
[1] "changepoint"

I need to get the result back in C# to print values, to draw a graph, to identify what change points have been identified, etc. Any suggestions please.


回答1:


This property/key of the S4 object is returning an array which contains change points.

GenericVector gvec = s4["param.est"].AsList();
NumericVector nvec = gvec[0].AsNumeric();


来源:https://stackoverflow.com/questions/45567909/retrieve-result-from-r-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!