Data frame handling in C# connected with R

466 views Asked by At

I am trying to handle a dataframe in R through a WPF application. I have used RDotNet as an interface between R and C# and my code snippet is as follows

DataFrame mapp = engine_1.Evaluate("mapp").AsDataFrame();

I am unable to get specific columns or rows i.e unable to achieve mapp[1] type indexing. The entire data frame is getting returned.

I would appreciate if someone can suggest any approach, I am exploring Deedle and using DataGrid control.

Thanks!

1

There are 1 answers

0
j-m On BEST ANSWER

Well, if the mapp variable in R is indeed a data frame (we cannot tell from your snippet), it should indeed be returned as a data frame, what's the surprise? You can access it by single item indexing, integer or column name.

// cases <- expand.grid(x=1:3, y=letters[1:3])
var letterCases = engine.Evaluate("cases[,'y']").AsCharacter().ToArray();
// Equivalent:
var df = engine.GetSymbol("cases").AsDataFrame();
letterCases = df[1].AsCharacter().ToArray();
letterCases = df["y"].AsCharacter().ToArray();

You can find sample usage including (but optionally) some more advanced meshing of C# and R this onboarding guide , under solutions/Onboard Sample2