2014-03-26 50 views
0

我學習如何檢測時間序列中的異常,並使用TSA package中的detectAOdetectIO函數。我在循環中使用它們,但是它們的輸出不受抑制。據我所知,當你在循環或函數中使用某些函數時,它們的輸出將被抑制,直到你使用print()函數。所以我檢查了這些函數的源代碼,作者使用了print()。有沒有任何方法可以在不使用sink('/dev/null')的情況下抑制此輸出?不使用接收器抑制打印()

require(TSA) 

detected<-numeric(1000) 

for(i in 1:10){ 

    data<-rcauchy(1000) 
    model<-auto.arima(data) 

    #I don't want this to be printed 
    detected<-detectAO(model)$ind 

    #Only this 
    print(detected) 
} 
+0

你可以張貼一些最起碼的可重複的代碼? – nico

回答

1
require(forecast) ## for auto.arima?                                                   

for(i in 1:10){ 

    data <- rcauchy(1000) 
    model <- auto.arima(data) 

    ##I don't want this to be printed                                                   
    capture.output(detected <- detectAO(model)$ind) 

    ##Only this                                                         
    print(detected) 

} 
+0

謝謝,它完美無瑕。當然,我忘了預測。 –

+0

@SebastianOsiński可以隨意標記爲選定的答案,如果它解決了問題 –