Quantcast
Channel: R.NET
Viewing all articles
Browse latest Browse all 1634

New Post: Decomposing R Objects

$
0
0
Hi,

Just getting started with this. Have the basics working ... can get data into and out of R and run library functions. As a test case, I'm running a VAR model using the 'vars' library. A code fragment is below.

The question is this ... having gotten back a result object in a SymbolicExpression, what's the best approach to extracting the data you're looking for? So far, I'm going one step at a time through the debugger, looking for types. For example, in the code fragment, variables v1, v2, and v3 were created on 3 successive runs.

So, am getting what I need in this case, but it seems like there ought to be an easier way. Or is this just what has to be done for each new type of object that comes back?

Any insight appreciated and thanks for a very handy tool.

NumericMatrix varMatrix = engine.CreateNumericMatrix(input);
engine.SetSymbol("varMatrix", varMatrix);

engine.Evaluate("library(vars)");
engine.Evaluate("varTest <- VAR(varMatrix, p=9, type = \"both\")");
SymbolicExpression result = engine.Evaluate("predict(varTest, n.ahead=12, ci=0.95)");
var v1 = result.AsList();
var v2 = v1[1];
double[] v3 = v2.AsNumeric().ToArray();

Viewing all articles
Browse latest Browse all 1634

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>