2

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.

3
  • Your data is unclear; what are you not grouping by? I only see you using the Key in the select statement. Commented Apr 21, 2011 at 13:42
  • A sample of the data and expected results would help too... Commented Apr 21, 2011 at 13:42
  • Additional Info added. Thanks. Commented Apr 21, 2011 at 13:49

1 Answer 1

1

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); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.