I have a dataset which contains more than 50k rows. I decided to take average of the first fifty values, then second fifty values and so on (so that I will get half of the Dataset with average of 50 value groups).
Here is my code:
var Rate = (from dr in ds.Tables[0].AsEnumerable()
select new
{
rate = dr.Field<double>(columnName)
}.rate).ToList();
if (Rate.Count > 50)
{
var avg = Rate.CheckRateValue();
}
And here is the code for my extension method:
public static IEnumerable<double> CheckRateValue(this IEnumerable<double> values)
{
int i = 1;
int j = 0;
for (; i < values.Count(); )
{
yield return values.Skip(j * 2).Take(2).Average();
i = i + 2;
j++;
}
}
Problem :
It works fine but it’s slow. Does anyone have any suggestions on how to speed it up?
By using row_number() i solved it.