[R] sink function

Matt Shotwell shotwelm at musc.edu
Sat Jul 24 00:43:39 CEST 2010


I had addressed a problem similar to this only a few days ago. Please
see the following URL:

http://tolstoy.newcastle.edu.au/R/e11/help/10/07/1677.html

On Fri, 2010-07-23 at 08:45 -0400, nuncio m wrote:
> I have the following code to write the output from auto.arima function.  The
> issue is not in finding the model but to divert its out put
> fit to a file order_fit.txt. code runs but nothing is written to
> order_fit.txt
> where am I going wrong
> 
> library(forecast)
> for (i in 1:2) {
> filen = paste("file",i,".txt",sep="")
> data <- read.table(filen)
> dat1 <- data[,1]
> xt <- ts(dat1,start=c(1978,11),end=c(2006,12),frequency=12)
> #dat1[dat1 == -99.989998] <- NA
> if (min(dat1) != max(dat1)){
> fit <- auto.arima(xt,D=1)
> 
> *sink(file="order_fit.txt")
> fit
> sink()*
> 
> residfit <- residuals(fit)
> filenou1 = paste("fileree",i,"_out",".txt",sep="")
> residfit
> write.table(residfit,filenou1,sep="\t",col.names=FALSE,row.names=FALSE,quote=FALSE)
> 
> }else{
> *fiit <- "ARIMA(-6,-6,-6)(-6,-6,-6)[12]"
> sink(file="order_fit.txt")
> fiit
> sink()*
> filenou1 = paste("fileree",i,"_out",".txt",sep="")
> residfit=rep(-99.99,338)
> residfit
> write.table(residfit,filenou1,sep="\t",col.names=FALSE,row.names=FALSE,quote=FALSE)
> rm(data,dat1,residfit,xt)
> }
> }
> 

--



More information about the R-help mailing list