Is there a way to get average of values in a field based on variables in another field? For example for the following input
a x 3
b y 4
a y 2
b x 5
b x 20
I want this output
a 2.5
b 9.67
I found this awk script to get average for values in a column
awk '{ total += $3; count++ } END { print total/count }' file.txt
but how can I add for loop in it to have the average for every variable in column 1?
The file is tab-separated.
Thank you