[英]Suppress output of stationarity test that is printed to screen
How do I get the stationarity
test from the fractal package
in R to not print any output to the screen. 如何从R中的
fractal package
中获得stationarity
测试,以便不将任何输出打印到屏幕上。
For example, with the shapiro.wilk
test when setting the result as a variable it does not give any output as follows 例如,使用
shapiro.wilk
测试将结果设置为变量时,它不会提供任何输出,如下所示
lg.day.ret.vec <- rnorm(100, mean = 5, sd = 3)
shap.p <- shapiro.test(lg.day.ret.vec)$p.value
This is the case for most tests but when I do it for the stationarity
test I get some output in the r console. 这是大多数测试的情况,但是当我为
stationarity
测试时,我在r控制台中获得了一些输出。
library(fractal)
stat.p <- attr(stationarity(lg.day.ret.vec),"pvals")[1]
1
2
3
4
5
6
N = 2609, nblock = 11, n_block_max = 238, dt = 1.0000
7
8
9
10
11
12
13
14
15
16
17
18
In fact, you can suppress the output to R console by rerouting it. 实际上,您可以通过重新路由来抑制输出到R控制台。 Two methods are available in R utils ,
sink
, and capture.output
. R utils ,
sink
和capture.output
中提供了两种方法。 Both methods are intended to send output to a file. 这两种方法都旨在将输出发送到文件。
Since you want to suppress the output of a single expression, you can use capture.output
, with file=NULL
(default). 由于要抑制单个表达式的输出,因此可以使用
capture.output
, file=NULL
(默认值)。 This will return your output as a string. 这将以字符串形式返回输出。 To prevent showing this returned string in the R console, you can use
invisible
. 要防止在R控制台中显示此返回的字符串 ,可以使用
invisible
。
The final code can be: 最终的代码可以是:
library(fractal)
lg.day.ret.vec <- rnorm(100, mean = 5, sd = 3)
shap.p <- shapiro.test(lg.day.ret.vec)$p.value
invisible(capture.output(
stat.p <- attr(stationarity(lg.day.ret.vec),"pvals")[1]
))
Hope this helps. 希望这可以帮助。 Let me know if not.
如果没有,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.