[mdlug] simple stats from piping numbers into R?

Robert Citek robert.citek at gmail.com
Thu Apr 15 17:33:35 EDT 2010


How can I get some simple stats from a data stream of numbers using R?

Here's what I would like to do:

$ seq 1 100 | stats.r
 Min.   :  1.00
 1st Qu.: 25.75
 Median : 50.50
 Mean   : 50.50
 3rd Qu.: 75.25
 Max.   :100.00

Where stats.r is an R script that returns simple stats on the data.

Here is what I am currently doing:

$ seq 1 100 > file.csv
$ R
> num <- read.csv("file.csv",head=FALSE)

> summary(num)
      V1
 Min.   :  1.00
 1st Qu.: 25.75
 Median : 50.50
 Mean   : 50.50
 3rd Qu.: 75.25
 Max.   :100.00

That works, but I'd prefer to pipe the data in rather than go through
the intermediary of a file or a named pipe.

Regards,
- Robert



More information about the mdlug mailing list