1.合計
void main() {
final list = [1, 2, 3, 4, 5];
final sum = list.reduce((a, b) => a + b);
print(sum); // 15
}
2.最大値、最小値
import 'dart:math';
void main() {
print([1,2,8,6].reduce(max)); // 8
print([1,2,8,6].reduce(min)); // 1
}
3.平均
void main() {
final list = [1, 2, 3, 4, 5];
final mean = list.reduce((a, b) => a + b) / list.length;
print(mean) // 3;
}
4.中央値
void main() {
list.sort();
final list = [1, 2, 3, 4, 5];
final length = list.length;
int median;
if (length % 2 == 1) {
median = list[(length/2 + 0.5).toInt()];
} else {
median = ((list[length~/2] + list[length~/2 + 1]) ~/ 2);
}
print(median) // 3;
}
5.標準偏差
import 'dart:math';
void main() {
final list = [1, 2, 3, 4, 5];
final mean = list.reduce((a, b) => a + b) / list.length;
final standardDeviation = sqrt(
final squaredDifference = list.map((current) {
var difference = current - mean;
return pow(difference, 2);
}).reduce((previous, current) =>
previous + current
) / list.length;
);
print(standardDeviation); // 1.58113883008
}