Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

stats for a row not a column

223 views
Skip to first unread message

Jörg Buchholz

unread,
Feb 4, 2016, 2:42:48 PM2/4/16
to
Hello,

is there a way to use the stats command for a row?

Data:
- a b c
A 1 2 3
B 1 - 5
C 1 2 3

stats 'file' u 3

Records: 2
Mean: 2.0000
Sum: 4.0000

So this is for the col b.

I want to do this for the row B, but I don't have a good idea to do this.

Jörg

Jörg Buchholz

unread,
Feb 5, 2016, 12:34:43 PM2/5/16
to
So I try the option "every", on a plot every ::2::2 only takes the third
line/row.

stats 'file' every ::2::2 matrix

But it takes the third column and not the third row. Another different
between "stats using" and "stats every" ist the handling of NaN.

"stats using" handle NaN as "nothing", so strings will be ignored.
"stats every" handle NaN as zero.

So the sum is the same but the mean is different.

Jörg




Karl Ratzsch

unread,
Feb 5, 2016, 1:46:47 PM2/5/16
to
Am 04.02.2016 um 20:42 schrieb Jörg Buchholz:
>
> is there a way to use the stats command for a row?
>

It should be possible with "stats matrix", if you limit the yrange
in the right way?

Karl

Jörg Buchholz

unread,
Feb 5, 2016, 3:09:18 PM2/5/16
to
I try it with the option "every", but get also only colums and not rows.

Next problem with "stats matrix" is "mean".

"B 1 - 5" mean in "stats matrix" is 1.5 (6/4). In "stats using" the mean
is 3.0 (6/2). That is what I wont to have. So for me there a two
problems and no solution.

Is it intentional that "stats matrix" and "stats using" calculate the
mean in two different ways?

Jörg

Karl Ratzsch

unread,
Feb 7, 2016, 11:54:37 AM2/7/16
to
Hm. "every" is not what you want. I'm not even sure how it should work
with matrix data.

Limiting the y range with "stats matrix" indeed doesn't work:

$dat << EOD
10 10 10
20 20 20
40 40 40
100 1000 10000
EOD

stats [:] [1:1] $dat matrix

The second range specifier refers to the data (z) values, not the
constructed abscissa values. "set yrange" has no effect.

And there seems to be a general problem with stat matrix, it interacts
strangely with splot:

splot $dat
stats $dat matrix

gives the mean of the x-axis values (here 0,1,2), as long as that splot
is the last plot command. If you give

plot $dat
stats $dat matrix

the correct mean is again returned.



Jörg Buchholz

unread,
Feb 8, 2016, 1:32:20 PM2/8/16
to
As a workaround I rotate the matrix and use "stats using" to get the
relevant mean.

data = 'matrix.dat'
system (sprintf("cat %s | rs -T >%s.trans",data,data))

Jörg

Karl Ratzsch

unread,
Feb 9, 2016, 4:15:50 AM2/9/16
to
Am 07.02.2016 um 17:54 schrieb Karl Ratzsch:
> Limiting the y range with "stats matrix" indeed doesn't work:
>
> $dat << EOD
> 10 10 10
> 20 20 20
> 40 40 40
> 100 1000 10000
> EOD
>
> stats [:] [1:1] $dat matrix
>
> The second range specifier refers to the data (z) values, not the
> constructed abscissa values. "set yrange" has no effect.
>
> And there seems to be a general problem with stat matrix, it interacts
> strangely with splot:
>
> splot $dat
> stats $dat matrix
>
> gives the mean of the x-axis values (here 0,1,2), as long as that splot
> is the last plot command. If you give
>
> plot $dat
> stats $dat matrix
>
> the correct mean is again returned.

I've filed a bug on https://sourceforge.net/p/gnuplot/bugs/1739/ for this.

Ethan A Merritt

unread,
Feb 9, 2016, 2:44:42 PM2/9/16
to
Jörg Buchholz wrote:

> On 05.02.2016 19:46, Karl Ratzsch wrote:
>> Am 04.02.2016 um 20:42 schrieb Jörg Buchholz:
>>>
>>> is there a way to use the stats command for a row?

Not that I know of.

>> It should be possible with "stats matrix", if you limit the yrange
>> in the right way?

I don't think you can use xrange or yrange to limit the indices
in a matrix. But I could be wrong on this point.


> Next problem with "stats matrix" is "mean".
>
> "B 1 - 5" mean in "stats matrix" is 1.5 (6/4). In "stats using" the mean
> is 3.0 (6/2). That is what I wont to have. So for me there a two
> problems and no solution.
>
> Is it intentional that "stats matrix" and "stats using" calculate the
> mean in two different ways?

Yes.

"stats using N" will only look at column N

"stats matrix" will look at all entries in the matrix

Note that normally in the latter case you want "stats matrix using 3",
since that is what will get you the value of the element matrix[i][j].
In the absence of an explicit using specification it probably
defaults to the equivalent of "matrix using 1", which would give
you the x coordinate of each matrix entry rather than its value.

Ethan

Karl Ratzsch

unread,
Feb 9, 2016, 4:48:44 PM2/9/16
to
Am 09.02.2016 um 20:44 schrieb Ethan A Merritt:
>> On 05.02.2016 19:46, Karl Ratzsch wrote:
>>> It should be possible with "stats matrix", if you limit the yrange
>>> in the right way?
>
> I don't think you can use xrange or yrange to limit the indices
> in a matrix. But I could be wrong on this point.

limiting the xrange works, but yrange setting gets ignored
0 new messages