C# LINQ 查询
我有以下查询:
var results = from theData in GeometricAverage
group theData by new { study = theData.study, groupNumber = theData.groupNumber, GeoAverage= theData.GeoAverage } into grp
select new
{
study = grp.Key.study,
groupNumber = grp.Key.groupNumber,
TGI = testFunction(grp.Key.GeoAverage, Also here I want to pass in the GeoAverage for only group 1 (but for each individual study))
};
我想要做的是,对于每个研究,都有多个组,每个组都有一个 GeoAverage 数字。 TGI 是通过将每个组的 GeoAverage 数据和第 1 组(每个研究)的 GeoAverage 数据传递到 testFunction 来计算的。我不知道如何仅为组 1 传递值。
希望这是有道理的。
编辑:数据样本:
Study Group GeoAverage
1 1 3
1 2 5
1 3 6
2 1 2
2 2 3
2 3 9
因此,对于上述数据,我希望每个组的每个 GeoAverage 数字都根据同一研究中第 1 组的 GeoAverage 数字进行评估。因此,如果我说一个函数:
int foo(int a, int b)
{
return a * b;
}
使用上面的数据,我将首先根据自身评估研究 1、组 1,因此传入 GeoAverage 3 两次并返回 9。对于研究 1、组 2,在 5 处传入组 2 GA,研究组 1 的 GA 为 3,返回 15。
I have the following query:
var results = from theData in GeometricAverage
group theData by new { study = theData.study, groupNumber = theData.groupNumber, GeoAverage= theData.GeoAverage } into grp
select new
{
study = grp.Key.study,
groupNumber = grp.Key.groupNumber,
TGI = testFunction(grp.Key.GeoAverage, Also here I want to pass in the GeoAverage for only group 1 (but for each individual study))
};
What I want to do is that for each study, there are multiple groups with a GeoAverage figure for each group. The TGI is calculated by passing the GeoAverage figure for each group and the GeoAverage figure for group 1 (on each study) into the testFunction. I can't figure out how to pass in the value just for group 1.
Hope this makes sense.
EDIT: Sample of data:
Study Group GeoAverage
1 1 3
1 2 5
1 3 6
2 1 2
2 2 3
2 3 9
So, for the above data, I would want each GeoAverage figure for each group, to be evaluated against the GeoAverage figure of group 1 within that same study. So if I have say a function:
int foo(int a, int b)
{
return a * b;
}
Using the data above, I would first evaluate study 1, group 1 against itself, so pass in GeoAverage 3 twice and return 9. For Study 1, group 2, pass in group 2 GA at 5, and that studys group1 GA at 3, returning 15.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在已经解决了。我循环访问希望存储值的数据集合,并使用以下两个 LINQ 查询:
Have now worked it out. I iterate through a collection of data that I want the value to be stored against and use the following two LINQ queries: