[R] incorrect multiple outputs

biscuit bawan03 at googlemail.com
Thu Dec 10 18:39:04 CET 2009


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.




More information about the R-help mailing list