Apologies,
I didn't explain this clearly. The Rscript is called by a perl script, which 
creates "input_file.txt" by inserting 288 lines of (reformatted) data for each 
data file in the directory.  So the Rscript will (and is doing) run the loop a 
number of times equal to the number of files the perl script read in. The 
problem is that it should only create the data.frame and write to the file 
after the last iteration, but it's (creating and)writing the complete 
data.frame every iteration.
Sent using BlackBerry® from Orange

-----Original Message-----
From: jim holtman <jholt...@gmail.com>
Date: Thu, 10 Dec 2009 18:00:54 
To: biscuit<bawa...@googlemail.com>
Cc: <r-help@r-project.org>
Subject: Re: [R] incorrect multiple outputs

If I rad you code right, file.rows is equal to 1 and your 'for' loop will
only iterate once.  Is that what you were expecting?

No reproducible code provided, so that is my best guess.

>file.rows<- c(nrow(file)/288)  # "input_file.txt" contains 288 reformatted
lines for each original data file
...
>for (k in 1:file.rows){  # iterates code for each 288 line block of
"input_file.txt"
...

On Thu, Dec 10, 2009 at 11:39 AM, biscuit <bawa...@googlemail.com> wrote:

>
> HI,
> I'm having trouble with a piece of Rscript which keeps outputting
> incorrectly. it's something like this: the code reads in from a file which
> contains (reformated) input
>
> >file<-read.table(file="input_file.txt",sep="\t")[,c(1,3:5)]
> >
> >file.rows<- c(nrow(file)/288)  # "input_file.txt" contains 288 reformatted
> lines for each original data file
> ...
> >for (k in 1:file.rows){  # iterates code for each 288 line block of
> "input_file.txt"
> ...
> >cv[k] <- 100*(sd(x.blank)/mean(x.blank))
> >t[k] <-
> (mean(x.note)-mean(x.blank))/sqrt(((sd(x.note)^2)/8)+((sd(x.blank)^2)/16))
> >t11[k] <-
> (sqrt(8)*(mean(x.note11)-mean(x.blank)))/sqrt(sd(x.note11)^2+sd(x.blank)^2)
> >}
> >
>
> >all.data<-data.frame(barcodes,t=format(as.numeric(t),digits=3),t11=format(as.numeric(t11),digits=3),cv=format(as.numeric(cv),digits=3))
> >write.table(all.data, file=
> "R_drug_plot.log",append=TRUE,sep="\t",row.names=FALSE)
>
> this all works correctly except that I believed it would output to file
> after completing the loop, instead it's writing to file every iteration. so
> the output file looks like:
>
> headers
> a1
> headers
> a1
> a2
> headers
> a1
> a2
> a3
> ...
>
> I have checked the missing sections of code and can confirm there are no
> missing/additional brackets. Has anyone any idea why this is happening and
> what I can do about it?
> --
> View this message in context:
> http://n4.nabble.com/incorrect-multiple-outputs-tp957192p957192.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to