[mdlug] simple stats from piping numbers into R?
Robert Citek
robert.citek at gmail.com
Mon Apr 19 22:49:42 EDT 2010
On Mon, Apr 19, 2010 at 8:57 PM, Michael Corral <micorral at comcast.net> wrote:
> 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)
Thanks, Michael. That'll work in a pinch for small datasets. Looks
like for larger sets I'll have to find some other way.
One way I've been exploring is piping a script to R, using bash's
here-document feature with variable interpolation. Works even for 1
MM numbers:
$ cmd="seq 1 1000000" ; { cat <<eof
summary(read.csv(pipe("$cmd"), head=FALSE))
eof
} | time -p R --slave
V1
Min. : 1
1st Qu.: 250001
Median : 500000
Mean : 500000
3rd Qu.: 750000
Max. :1000000
real 12.50
user 15.98
sys 0.26
I can then substitute various commands for the cmd variable. Not
ideal, but will work.
Regards,
- Robert
More information about the mdlug
mailing list