[R] Use R in a pipeline as a filter

2007-06-07 Thread mw-u2
Hi,

how can I use R in a pipline like this

 $ ./generate-data | R --script-file=Script.R | ./further-analyse-data > 
result.dat

Assume a column based output of ./generate-data, e.g. something like:
1 1 1
2 4 8
3 9 27
4 16 64

The R commands that process the data should come from Script.R and should print 
to stdout (Script.R could for example calculate the square of every entry or 
calculate the mean of the columns, ...)

The output should be printed to stdout, such that further-analyse-data can use 
the output.

Can some R expert code that for me please? I would be very happy. I am also 
happy about information how to do that myself although I dont think I know 
enough to do that myself.

Thank you for your consideration,

Micha
-- 
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] automated data processing

2006-06-13 Thread mw-u2
I have many files (0.4.dat, 0.5.dat, ...) of which I would like to calculate 
mean value and variance and save the output in a new file where each line 
shouldlook like: "0.4 mean(0.4.dat) var(0.4.dat)" and so on. Right now I got a 
a simple script that makes me unhappy:

1. I run it by "R --no-save < script.r > out.dat" unfortunately out.dat has all 
the original commands in it and a "[1]" infront of every output

2. I would love to have a variable running through 0.4, 0.5, ... naming the
datafile to process and the first column in the output.

My script looks like:

data <- read.table("0.4.dat"); E <- data$V1[1000:length(data$V1)];
c(0.4, mean(E), var(E));
data <- read.table("0.5.dat"); E <- data$V1[1000:length(data$V1)];
c(0.5, mean(E), var(E));

And that would be its output:
#[1] 0.400 -1134.402  5700.966
#> data <- read.table("0.5.dat"); E <- data$V1[1000:length(data$V1)];
#> c(0.5, mean(E), var(E));
#[1] 0.500 -1787.232  2973.692

Thanks
-- 


Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html