Ista,

Here is the full code:

file<-read.table(file="input_file.txt",sep="\t")[,c(1,3:5)]
file.rows<- c(nrow(file)/288)
full.array <- array(0,dim=c(8,file.rows,12))

cellnames <- rep("A",file.rows)
barcodes <- rep("A",file.rows)
t <- rep("A",file.rows)
t11 <- rep("A",file.rows)
cv <- rep("A",file.rows)

for (k in 1:file.rows){

plate<- file[(((k-1)*288)+1),1]

barcodes[k] <- levels(plate)[plate]

l <- k*288
a <- l-287
x<-file[a:l,]
x.array<-matrix(0,ncol=12,nrow=8)
n.array<-matrix(0,ncol=12,nrow=8)
x.blank2 <- matrix(0,ncol=3,nrow=24)
x.nodrug2 <- matrix(0,ncol=6,nrow=24)
value <- data.frame(conc=0,fluor=2)

# reformat (mean) input data into 96 well format
q<-1
for (m in 1:8){ for (n in 1:12){ p<- 3*q; x.array[m,n] <-
mean(as.matrix(x[(p-2):p,2:4])); q <- q+1; if (n == 1){z<-3*m;
x.blank2[(z-2):z,]<-as.matrix(x[(p-2):p,2:4])}; if
(n==11){z<-3*m;x.nodrug2[(z-2):z,1:3]<-as.matrix(x[(p-2):p,2:4])}; if
(n==12){z<-3*m; x.nodrug2[(z-2):z,4:6]<-as.matrix(x[(p-2):p,2:4])}}}
x.blank<-c(x.blank2[,1],x.blank2[,3],x.blank2[,2])

x.nodrug
<-c(x.nodrug2[,1],x.nodrug2[,2],x.nodrug2[,3],x.nodrug2[,4],x.nodrug2[,5],x.nodrug2[,6])
x.nodrug11 <-c(x.nodrug2[,1],x.nodrug2[,2],x.nodrug2[,3])

# calculate output values

cv[k] <- 100*(sd(x.blank)/mean(x.blank))
t[k] <-
(mean(x.nodrug)-mean(x.blank))/sqrt(((sd(x.nodrug)^2)/8)+((sd(x.blank)^2)/16))
t11[k] <-
(sqrt(8)*(mean(x.nodrug11)-mean(x.blank)))/sqrt(sd(x.nodrug11)^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(format(t,digits=6), file= "R_drug_plot.log",append=TRUE,sep="\t")
write.table(all.data, file=
"R_drug_plot.log",append=TRUE,sep="\t",row.names=FALSE)

When I first tried the mail list wouldn't let me send it as it contains the
word "drug" too many times! so I only included the problematic parts.
Rich

2009/12/11 Ista Zahn <istaz...@gmail.com>

> The lack of a reproducible example is a bigger problem than any lack
> of clarity of the explanation.
>
> -Ista
>
> On Fri, Dec 11, 2009 at 2:08 AM,  <bawa...@googlemail.com> wrote:
> > 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>
> <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<http://www.r-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
>
>
> --
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychology
> http://yourpsyche.org
>

        [[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