I want to compute average across columns for a table(that I get as a result from stats command). I am trying to do somrthing similar to addtotals(sum) but for average. I can of course use addtotals and divide it by no of columns to get the average. But, number of columns vary on a row by row basis.
For eg:-
......... Col1 Col2 Col3 Avg
Row1 .... 2 .. 3 .. 4 .... 3
Row2 .... ..... 3 .. 5 .... 4
Row3 .... ........... 5 .... 5
This question is answered here: http://answers.splunk.com/questions/6269/need-to-calculate-weighted-average-across-columns-like-addt...
The key is the makemv command.
This question is answered here: http://answers.splunk.com/questions/6269/need-to-calculate-weighted-average-across-columns-like-addt...
The key is the makemv command.
Seems to me that you'd have to come up with the count of the non-null columns:
eval col_count=if(isnull(col1,0,1))+if(isnull(col2,0,1))+if(isnull(col3,0,1))
Either that, or it might not be a bad idea to rethink how the stats command is being done. There might be better ways to get the result you want.
This would work if you roughly know the no of columns . What if we don't know the number of cols before ?