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

New Post: Returning a time series to .net using r packages xts or zoo.

$
0
0
Its not that easy, getting types sent from R over to C# when the C# side can't predeclare them is difficult. I know there's some dynamic stuff for DataFrames, but I know little about it. On the static side, you need to do something like this. I'm sure there's alternative ways to make this work, but here's mine:
[DataFrameRow]
public class RowData
{
    [DataFrameColumn("Date")]
    public double Date { get; set; }

    [DataFrameColumn("IndexValues")]
    public double IndexValues { get; set; }
}
private static void Main(string[] args)
{
    var rEngine = REngine.GetInstance();
    const string command = @"library(xts); IndexValues <- xts(rnorm(10), as.POSIXlt(Sys.Date()+1:10));
                            data.frame(Date = index(IndexValues), IndexValues, row.names=NULL)";
    var df1 = rEngine.Evaluate(command).AsDataFrame();

    var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    var dates = df1.GetRows<RowData>().Select(s => epoch.AddSeconds(s.Date)).ToList();
}


Viewing all articles
Browse latest Browse all 1634

Trending Articles



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