summaryrefslogtreecommitdiff
path: root/lin_reg2.awk
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lin_reg2.awk14
1 files changed, 10 insertions, 4 deletions
diff --git a/lin_reg2.awk b/lin_reg2.awk
index 450f0f0..d6097e3 100644
--- a/lin_reg2.awk
+++ b/lin_reg2.awk
@@ -3,6 +3,7 @@
### lin_reg2.awk
# simple linear regression between columns
+
BEGIN {
sign = "[+-]?"
decimal = "[0-9]+[.]?[0-9]*"
@@ -11,22 +12,26 @@ BEGIN {
number = "^" sign "(" decimal "|" fraction ")" exponent "$"
}
+
+# column headers
NR == 1 {
for (n=1; n<=NF; n++)
($n ~ number) ? header[n] = "col" n : header[n] = $n
}
+
+# read input data
NF > 0 {
- if (NF > nf_max)
- nf_max = NF
+ (NF > nf_max) ? nf_max = NF : nf_max = nf_max
- ### iterate over columns
+ # columns
for (y=1; y<=nf_max; y++) {
if ($y == header[n])
continue
+
if ($y ~ number) {
- ### mean
+ # mean
count[y] += 1
sum[y] += $y
sum2[y] += $y*$y
@@ -75,6 +80,7 @@ NF > 0 {
}
}
+
END {
for (y=1; y<=nf_max; y++) {
for (x=1; x<=nf_max; x++) {