将p值写入R中的文件

Dia*_*len 4 r file

有人可以帮我解决这段代码.在循环中,我将p值保存在f中,然后我想将p值写入文件,但我不知道用哪个函数写入文件.我写入函数出错了.

{
f = fisher.test(x, y = NULL, hybrid = FALSE, alternative = "greater",
                conf.int = TRUE, conf.level = 0.95, simulate.p.value = FALSE)

write(f, file="fisher_pvalues.txt", sep=" ", append=TRUE)
}

Error in cat(list(...), file, sep, fill, labels, append) : 
  argument 1 (type 'list') cannot be handled by 'cat'
Run Code Online (Sandbox Code Playgroud)

Spa*_*man 6

fisher.test的返回值是(如果您阅读文档):

值:

 A list with class ‘"htest"’ containing the following components:
Run Code Online (Sandbox Code Playgroud)

p.value:测试的p值.

conf.int:优势比的置信区间.仅出现在2乘2的情况下,如果参数'conf.int = TRUE'.

R等不知道如何将这样的东西写入文件.更确切地说,它不知道您希望如何将其写入文件.

如果你只想写p值,那么得到p值并写下:

 write(f$p.value,file="foo.values",append=TRUE)
Run Code Online (Sandbox Code Playgroud)