[mdlug] simple stats from piping numbers into R?

Michael Corral micorral at comcast.net
Mon Apr 19 20:57:55 EDT 2010


2010-04-15, Monsieur Robert Citek a ecrit:
> 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.

You could do it like this:

R --vanilla --slave --args $(seq 1 100) < stats.r

where the file stats.r consists of these two lines:

num <- as.numeric(commandArgs(TRUE))
summary(num)


Michael



More information about the mdlug mailing list