[R] Capturing the whole output using R

arun smartpink111 at yahoo.com
Sun Aug 25 04:45:45 CEST 2013


Hi,

May be this helps:
#Creating some dummy data.  

set.seed(24)
lst1<-lapply(1:8,function(x) ts(sample(1:25,20,replace=TRUE)))
set.seed(49)
lst2<-lapply(1:8,function(x) ts(sample(1:45,20,replace=TRUE)))


??Find_Max_CCF()
#No vignettes or demos or help files found with alias or concept or
#title matching ‘Find_Max_CCF’ using regular expression matching.


Found a function with the same name from 

http://r.789695.n4.nabble.com/ccf-function-td2288257.html
 capture.output(do.call(rbind,lapply(seq_along(lst1),function(i) Find_Max_CCF(lst1[[i]],lst2[[i]]))),file="output.txt")


#output.txt
#         cor lag
#10 0.4799088  -1
#17 0.2060688   6
#16 0.3716986   5
#6  0.3701101  -5
#8  0.3964724  -3
#4  0.2942228  -7
#15 0.3191763   4
#9  0.3654471  -2

A.K.





capture.output(do.call(rbind,lapply(seq_along(lst1),function(i) Find_Max_CCF(lst1[[i]],lst2[[i]]))))
#[1] "         cor lag" "10 0.4799088  -1" "17 0.2060688   6" "16 0.3716986   5"
#[5] "6  0.3701101  -5" "8  0.3964724  -3" "4  0.2942228  -7" "15 0.3191763   4"
#[9] "9  0.3654471  -2"





Hi, 
I am using following code to Find lag at which cross correlation is maximum ccf( ), where Find_Max_CCF(x,y) 
returns the max cross correlation. where x[i], y[i] are two different time series, i=1,2 ,...,8 

for( i in 1:8) 
{ 
{c=Find_Max_CCF ( x [ i ], y [ i ] ) ) 
} 

Now, I want to capture the whole 8 results in the same excel sheet. I used 
capture.output(Find_Max_CCF ( x [ i ], y [ i ] ) ), file="output.txt") 

But this is giving me only the last result that is cross correlation for last two time series, x[8], y[8]. 
Please help... 

Thanks in advance.. 

Shilpa Rai



More information about the R-help mailing list