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
Not sure what your increments are, but something like this might work:
result <- NULL
for (i in 4:5){
x <- read.table(paste('0.', i, '.dat', sep=''))
E <- data$V1[1000:length(data$V1)]
result <- rbind(result, c(paste('0.', i, sep=''), mean(E),
var(E)
}
# you can then output 'result' to a file
On 6/13/06, mw-u2@gmx.de <mw-u2@gmx.de> wrote:>
> 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.dathas 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
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390 (Cell)
+1 513 247 0281 (Home)
What is the problem you are trying to solve?
[[alternative HTML version deleted]]
Hi,
Put all you .dat files in one directory ('c:/data' for example) and do
this:
finaltable <-NULL
folder <-dir('c:/data')
for (i in folder){
table1 <-read.table(i)
mean1 <-mean(table1$V1)
var1 <-var(table1$V1)
rowname <-paste(i)
finaltable <-rbind(finaltable,c(rowname,mean1,var1))
}
Neuro
>From: mw-u2 at gmx.de
>To: r-help at stat.math.ethz.ch
>Subject: [R] automated data processing
>Date: Tue, 13 Jun 2006 21:34:40 +0200
>
>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 at 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