public void DataViewGroupByClause() { DataView original = GetTestFrame();//.WhereNotNull("male"); DataFrame grouped = original.GroupBy("male", v => v.Column <double>("height").Mean(), "meanHeight"); foreach (DataRow row in grouped.Rows) { object value = row["male"]; // r["male"] == value doesn't work, because this is an object comparison, // and two equal values boxed to objects are not equal. This is a problem. DataView selected = original.Where <bool?>("male", m => m.Equals(value)); //DataView selected = original.Where(r => (r["male"] == value)); double height = selected.Column <double>("height").Mean(); Assert.IsTrue((double)row["meanHeight"] == height); } }
public void DataViewOrderByColumnFunc() { DataView original = GetTestFrame(); // This should support nulls DataView reordered = original.OrderBy("name"); //DataView reordered = original.OrderBy<string>("name", String.Compare); Assert.IsTrue(reordered.Columns.Count == original.Columns.Count); Assert.IsTrue(reordered.Rows.Count == original.Rows.Count); List <string> reorderedCopy = original.Column <string>("name").ToList(); reorderedCopy.Sort(); DataColumn <string> reorderedColumn = reordered.Column <string>("name"); for (int i = 0; i < reorderedColumn.Count; i++) { Assert.IsTrue(reorderedColumn[i] == reorderedCopy[i]); } }