using System;
using System.Linq;
using System.Data;
class Test_Linq
{
static void Main()
{
DataTable table = new DataTable();
table.Columns.Add("class");
table.Columns.Add("data",typeof(double));
table.Rows.Add("A", 45.2);
table.Rows.Add("A", 45.8);
table.Rows.Add("A", 45.9);
table.Rows.Add("B", 45.1);
table.Rows.Add("B", 45.5);
table.AcceptChanges();
// 기초통계량 (전체)
double max = table.AsEnumerable().Max(r => r.Field<double>("data"));
double min = table.AsEnumerable().Min(r => r.Field<double>("data"));
double mean = table.AsEnumerable().Average(r => r.Field<double>("data"));
double sum = table.AsEnumerable().Sum(r => r.Field<double>("data"));
double qsm = table.AsEnumerable().Sum(r => Math.Pow(r.Field<double>("data"), 2));
double stdDev = Math.Sqrt((qsm-table.Rows.Count*(mean*mean))/(table.Rows.Count-1));
stdDev = Math.Round(stdDev, 4);
Console.WriteLine("**. 기초통계량(전체)");
Console.WriteLine("개 수 = {0}", table.Rows.Count);
Console.WriteLine("최 대 값 = {0}", max);
Console.WriteLine("최 소 값 = {0}", min);
Console.WriteLine("평 균 = {0}", mean);
Console.WriteLine("합 계 = {0}", sum);
Console.WriteLine("제 곱 합 = {0}", qsm);
Console.WriteLine("표준편차 = {0}", stdDev);
Console.WriteLine();
}
}