[英]Accessing and extracting Data Frame Results - R.NET
I run a R script
from C#
and get the results in a dataframe
as : 我从C#
运行R script
,并在dataframe
获取结果:
var OUTPUT = engine.GetSymbol("detail.dt").AsDataFrame();
OUTPUT dataframe
has let's say 3 columns as: OUTPUT dataframe
的3列为:
NAME Month Rate
Rob 1 100
Rob 2 150
Rob 3 500
Ned 1 200
Ned 2 500
Sansa 1 500
Sansa 2 1000
I can extract individual column values as : 我可以将单个列值提取为:
var Name = OUTPUT[0].AsEnumerable().ToList();
var Month = OUTPUT[1].AsNumeric().ToList();
var Rate = OUTPUT[2].AsNumeric().ToList();
My question is instead of extracting column by column values, I basically want to extract Month
and Rate
if user asks for " Rob
" or " Sansa
". 我的问题是,如果用户要求输入“ Rob
”或“ Sansa
”,我基本上想提取Month
和Rate
,而不是逐列提取值。 How do I extract Month
and Rate
values for a given Name
? 如何提取给定Name
Month
和Rate
值 ? Is there a better and faster way? 有没有更好更快的方法?
I would loop through the data.frame. 我会遍历data.frame。 Name appears to be duplicated in your data, but here's how you can get one of them: 名称似乎在您的数据中重复,但是您可以通过以下方法获取其中之一:
string userInput = "Rob";
int myMonth = 0;
int myRate = 0;
for (int i = 0; i < OUTPUT.RowCount; ++i)
{
if (OUTPUT[i, 0].ToString() == userInput) {
myMonth = Convert.ToInt32(OUTPUT[i, 1].ToString());
myRate = Convert.ToInt32(OUTPUT[i, 2].ToString());
break;
}
}
If you need all of them, get rid of the break statement, and pile them into a list or whatever data structure that suits you. 如果需要所有这些,请摆脱break语句,然后将它们堆积到列表或任何适合您的数据结构中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.