【问题标题】:error while writing file after adonis analysisadonis分析后写入文件时出错
【发布时间】:2020-07-11 21:26:25
【问题描述】:

我正在尝试使用以下代码编写排列分析的输出,但它显示错误,您能否建议我如何解决此错误?

R code

###adonis_calculation
BC <- phyloseq::distance(phyloseq_prop, "bray")
pmv =adonis(BC ~Season*Region, as(sample_data(physeqN3), "data.frame"),permutations = 5000)
pmv

write.table(pmv, "permutation.16s.Root.txt")

Error:

              Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)
Season          1    1.2435 1.24348  17.229 0.07405  2e-04 ***
Region          2    5.3491 2.67457  37.058 0.31855  2e-04 ***
Season:Region   2    1.3222 0.66110   9.160 0.07874  2e-04 ***
Residuals     123    8.8773 0.07217         0.52866
Total         128   16.7921                 1.00000
---

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
  cannot coerce class ‘"adonis"’ to a data.frame
Calls: write.table ... data.frame -> as.data.frame -> as.data.frame.default
Execution halted

非常感谢

【问题讨论】:

  • 你可以试试library(broom); write.table(tidy(pmv), "permutation.16s.Root.txt")

标签: r vegan phyloseq


【解决方案1】:

输出不是data.frame格式,一个选项是用capture.output捕获输出

capture.output(pmv, file = "permutation.16s.Root.txt")

使用一个可重现的小例子

library(vegan)
data(dune)
data(dune.env)
pmv <- adonis(dune ~ Management*A1, data = dune.env)
capture.output(pmv, file  = "/Users/akrun/tmp/permutation.16s.Root.txt")
 

-输出

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-10
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    • 1970-01-01
    相关资源
    最近更新 更多