[mdlug] simple stats from piping numbers into R?
Robert Citek
robert.citek at gmail.com
Tue Apr 20 10:56:16 EDT 2010
On Tue, Apr 20, 2010 at 8:39 AM, Jonathan Billings <billings at negate.org> wrote:
> On Thu, Apr 15, 2010 at 05:33:35PM -0400, Robert Citek wrote:
>> That works, but I'd prefer to pipe the data in rather than go through
>> the intermediary of a file or a named pipe.
>
> I believe you can refer to "stdin" (I've also seen /dev/stdin) as the
> file in scan:
>
> % cat test.r
> #!/usr/bin/Rscript
>
> num <- scan("stdin",quiet=TRUE)
> summary(num)
>
> % seq 1 100 | ./test.r
> Min. 1st Qu. Median Mean 3rd Qu. Max.
> 1.00 25.75 50.50 50.50 75.25 100.00
Perfect! Rscript with -e and "stdin" were the trick. Here's exactly
what I wanted to do:
$ seq 1 1000000 |\
time -p Rscript -e 'summary(read.csv("stdin", head=FALSE))'
V1
Min. : 1
1st Qu.: 250001
Median : 500000
Mean : 500000
3rd Qu.: 750000
Max. :1000000
real 11.07
user 10.55
sys 0.20
Thanks for all the replies.
Regards,
- Robert
More information about the mdlug
mailing list