C# LINQ 查询

发布于 2024-11-03 03:39:05 字数 1140 浏览 0 评论 0原文

我有以下查询:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱给你人给你 2024-11-10 03:39:05

现在已经解决了。我循环访问希望存储值的数据集合,并使用以下两个 LINQ 查询:

foreach (var data in compoundData)
        {
            var controlValue = from d in GeometricAverage
                               where d.study == data.study
                               where d.groupNumber == "1"
                               select d.GeoAverage;

            var treatmentValue = from l in GeometricAverage
                                 where l.study == data.study
                                 where l.groupNumber == data.groupNumber
                                 select l.GeoAverage;


            data.TGI = CalculateTGI(controlValue, treatmentValue);

        }

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:

foreach (var data in compoundData)
        {
            var controlValue = from d in GeometricAverage
                               where d.study == data.study
                               where d.groupNumber == "1"
                               select d.GeoAverage;

            var treatmentValue = from l in GeometricAverage
                                 where l.study == data.study
                                 where l.groupNumber == data.groupNumber
                                 select l.GeoAverage;


            data.TGI = CalculateTGI(controlValue, treatmentValue);

        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文