Hi All,
I have some data like below.
Step1,Param1,Param2,Param3
1,2,3,4
2,3,4,5
2,4,5,6
3,0,1,2
3,0,0,0
3,2,1,3
........
so on
Where I need to find the median(arithmetic) of each column from Param1...to..Param3 for each set of Step1 values.
(Sort each specific column, if the total entries is even; my mean is sum of (Middle 2 values)/2 else the mean is the middle value itself.)
I got one script like below by searching in google
echo -e '6\n2\n4\n3\n1' | sort -n | awk '{arr[NR]=$1}
END { if (NR%2==1) print arr[(NR+1)/2]; else print (arr[NR/2]+arr[NR/2+1])/2}'
But this works on a single column of data.
I want someone to modify this or suggest some other code to make it work on all columns.
I want something like below
awk -F, -v VAR="$i" '$1==VAR{Some Condition}' input.csv
where I am scanning variable i (each unique value from column1) using for loop.
The Expected output is :
Median_of_Col2,Median_of_Col3,Median_of_Col4 etc.. (practically i have many columns in my input)
The output with the above input is
2,3,4
3.5,4.5,5.5
0,1,2
Thanks
Sidda