[R] Help to write to a file

Sarah Goslee sarah.goslee at gmail.com
Tue Oct 11 19:10:23 CEST 2011


Hi,

Inside a loop, you must explicitly wrap your summary() command and anything
else from which you expect output in a print() command.

Sarah

2011/10/11 Sergio René Araujo Enciso <araujo.enciso at gmail.com>:
> Dear all:
>
> I am having some problems to use the function "sink()". Basically I am doing
> a loop over two files which contain unit-root variables. Then on a loop, I
> extract every i element of both files to create an object called z. If z
> meets some requirements, then I perform a unit root test (ADF test),
> otherwise not. As this process is repeated several times, for each i I want
> to get the summary of the ADF test on a common file. For that I use the
> function "sink()". My code runs fine, but I do not get anything written on
> the text file where my results are supposed to be saved. The code is below
>
> setwd("C:\\Users\\Sergio René\\Dropbox\\R")
>
> library("urca")
>
> P1<-read.csv("2R_EQ_P_R1_500.csv")
> P2<-read.csv("2R_EQ_P_R2_500.csv")
>
> d<-(1:1000)
> sink ("ADF_results_b_1.txt")
>
> for (i in seq(d))
> {
> z.1<-P1[i]*-1-P2[i]*-1
> if (all(z.1<=0)) {r=1} else {if (all(z.1>=0)) {r=1} else {r=2}}
> if (r==1) {ADF<-ur.df(ts(z.1), lags=1, type='drift')}
> if (r==1) {summary(ADF)}
> }
> sink()
>
> Any suggestion of what I might be doing wroong?
>
> best regards,
>
> Sergio René
>



-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list