(Video materials in preparation)
tagavg : Calculates the average of records with the same key value
Usage : tagavg <k1> <k2> [<v1> <v2>] <file>
tagavg [key=<key>] [val=<val>] <file>
Option : +<n>
-<n>
Version : Tue Jan 9 09:02:34 JST 2024
Edition : 1
Calculates the average value of the specified field of all records
that have the same value in the specified key field. You can
specify the key field two ways, as starting key <k1> to ending key
<k2> (conventional notation) or <key> (keyword notation).
In conventional notation, the relationship of the fields must follow
this rule: <k1> <= <k2> < <v1> <= <v2>. In keyword notation, <key>
designates the field position as fllows:
single field TAGa TAGa field
contiguous fields TAGa/TAGb from TAGa field to TAGb field
combination TAGa@TAGb TAGa field and TAGb field
There is no limit on the length of the key field or on the number
of key fields. The key field can also contain multi-byte characters
such as Japanese.
The tag name specfying the field can be eclosed by braces {}. In
this case, tag names can include special charcter like "/" or "@".
Moreover, tag names can include pairs of braces.
If you specify the fields to be averaged as <v1> <v2> then all
fields from <v1> to <v2> are averaged. If you specify it as
val=<val> then use formats shown above for key=<key>. If you omit
the fields to be averaged then all fields except for the key fields
are averaged.
The average value will be calculated to the maximum number of digits
in the field values plus one. If you specify +<n> then this means
the maximum number of decimal plus <n>. If you specify -<n> then
the output will have exactly <n> decimal places.
$ fcols data
K1 K2 N1 N2 N3 N4 N5
01 New_Jersey 91 59 20 76 54
01 New_Jersey 46 39 8 5 21
01 New_Jersey 82 0 23 84 10
02 New_York 30.3 50.6 71.2 36.32 30.0
02 New_York 78.5 13 44 28 51.05
02 New_York 58 71.128 20.333 10 6
02 New_York 39.1 22.61 13.45 76.11 8
02 New_York 82.3 79.0 16.22 21.22 80.3
02 New_York 50.55 2.12 33.4 15.6 62
03 Connecticut 52 91 44 9 0
03 Connecticut 60 89 33 18 6
03 Connecticut 95 60 35 93 76
04 Massachusetts 92.44 56.63 83.123 96.71 75
04 Massachusetts 30.555 12.328 32.31 44.79 19.1
04 Massachusetts 48.24 66.93 23.1 71.5 24.11
04 Massachusetts 45.1 21.9 24.26 39.82 3.22
Take the average of N1 - N5 for each state.
$ tagavg K1 K2 data | fcols
K1 K2 N1 N2 N3 N4 N5
01 New_Jersey 73.0 32.7 17.0 55.0 28.3
02 New_York 56.458 39.7430 33.1005 31.208 39.558
03 Connecticut 69.0 80.0 37.3 40.0 27.3
04 Massachusetts 54.0838 39.4470 40.6983 63.205 30.358
key=<key> format
$ tagavg key=K1/K2 data | fcols
K1 K2 N1 N2 N3 N4 N5
01 New_Jersey 73.0 32.7 17.0 55.0 28.3
02 New_York 56.458 39.7430 33.1005 31.208 39.558
03 Connecticut 69.0 80.0 37.3 40.0 27.3
04 Massachusetts 54.0838 39.4470 40.6983 63.205 30.358
Output exactly one decimal place
$ tagavg -1 key=K1/K2 data
K1 K2 N1 N2 N3 N4 N5
01 New_Jersey 73.0 32.7 17.0 55.0 28.3
02 New_York 56.5 39.7 33.1 31.2 39.6
03 Connecticut 69.0 80.0 37.3 40.0 27.3
04 Massachusetts 54.1 39.4 40.7 63.2 30.4