News for hackers. Stuff that matters.
Re:Show HN: st – simple statistics from the command line by Sprint on Wednesday September 04, 2013 @08:08AM (#6326901)
I'd just use octave. It's as simple as

  $ octave
  octave:1> a=load('numbers.txt');  
  octave:2> sum(a)
  ans =  55
  octave:3> mean(a)
  ans =  5.5000
  octave:4> std(a)
  ans =  3.0277
  octave:5> quantile(a)
  ans =
  
      1.0000
      3.0000
      5.5000
      8.0000
     10.0000
etc
Re:Show HN: st – simple statistics from the command line by nferraz on Wednesday September 04, 2013 @08:18AM (#6326941)
I like octave and R!

The reason I wrote this script was to get quick results from the command line.

For instance: I could use grep, cut and other unix tools to get the numbers from a file and make quick calculations.

Of course, for complex processing I would use octave or R.

Re:Show HN: st – simple statistics from the command line by Sprint on Wednesday September 04, 2013 @08:22AM (#6326966)
Yeah, I was thinking about that and spent the past minutes to make me some Bash functions like:

  function mean() {
          octave -q --eval "mean = mean(load('$1'))"
  }
Then just run "mean numbers.txt".

I am sure your approach is much quicker, octave takes a good 0.5s(!) to load on my machine.

Re:Show HN: st – simple statistics from the command line by nferraz on Wednesday September 04, 2013 @08:42AM (#6327090)
Yup, octave requires more time to warm up.

Regarding speed, for simple calculations like sum, mean and variance, the bottleneck is in I/O.

Re:Show HN: st – simple statistics from the command line by asgeirn on Wednesday September 04, 2013 @08:35AM (#6327045)
Would you be able to use Octave for reading from stdin?
Re:Show HN: st – simple statistics from the command line by nferraz on Wednesday September 04, 2013 @08:43AM (#6327093)
Yes, Sprint suggested this:

    octave -q --eval "mean = mean(load('$1'))"
But, again, octave requires more time to warm up...
Re:Show HN: st – simple statistics from the command line by fluidcruft on Wednesday September 04, 2013 @10:46AM (#6327899)
That does not read the data from stdin. You could probably get it to work with some bash wizardry. But maybe not. I did spend some time on this a few years ago and it may have changed in the interim, but my memory is that I tried load("/dev/stdin") and using a fifo etc and it doesn't work (probably because load() uses some seeks to determine matrix data shape before reading data in i.e. data is read in as columns instead of reading in rows and transposing). At least that was my takeaway. At least if you want to use the load() builtin.

Basically you just need to write an octave function that reads values from the terminal.