grsousajunior
grsousajunior

Reputation: 778

stats command don't return expected value when using ranges

I'm have some weird behavior with stats command when using ranges. Consider the follow simple example.

$Data<<EOD
 1    10
 2    20
 3    30
 4    40
 5    50
 6    60
 7    70
 8    80
 9    90
10   100
EOD

stats [1:5] $Data u 1   nooutput 
print STATS_records # Result: 10; Expected: 5

stats [1:5] $Data u 1:2 nooutput
print STATS_records # It works fine

Why the first stats command don't return expected value? This affects all stats results. Is it a bug? Am I missing something? I'm using version 5.2 patchlevel 8.

Upvotes: 0

Views: 83

Answers (1)

theozh
theozh

Reputation: 25749

My attempt to explain this behavior:

If you do

stats [1:5] $Data u 1:2 nooutput

Column 1 corresponds to x and column 2 corresponds to y. With [1:5] you limit x from 1 to 5, hence 5 records.

If you do

stats [1:5] $Data u 1 nooutput

Column 1 is "kind of" y and the pseudocolumn 0 is "kind of" x, however, you are limiting x but not the pseudocolumn 0, hence 10 records.

So, if you do

stats [1:5] $Data u 1:1 nooutput

you will get the expected results and the expected statistics on column 1.

To have a look at all the STATS values type show var STATS.

But I'm just guessing... I'm sure @Ethan can tell.

Upvotes: 1

Related Questions