将非数据帧数据导出到R中的文本文件

时间:2018-06-14 09:30:28

标签: r dataframe phylogeny

这是我正在使用的代码,这创建了我感兴趣的stastistical测试的摘要

library(ape)
library(geiger)
library(caper)

taxatree <- read.tree("newicktest.tre")
LWEVIYRcombodata <- read.csv("LWEVIYR.csv")


LWEVIYRcombodataPGLS <-data.frame(Sum.of.percentage=LWEVIYRcombodata$Sum.of.percentage,OGT=LWEVIYRcombodata$OGT, Species=LWEVIYRcombodata$Species)

LWEVIYRcombodataPGLS$Species<-gsub(" ", "", LWEVIYRcombodataPGLS$Species)

comp.dat <- comparative.data(taxatree, LWEVIYRcombodataPGLS, "Species")

phylo.signal <- pgls((Sum.of.percentage) ~1, data=comp.dat, lambda="ML")

我用这句话打电话:

summary(phylo.signal)

然后将其保存为变量:

dataforexport <- summary(phylo.signal)

然而,这不允许我将它打印到常规文本文件,甚至是csv。

在尝试某事时:

write.table(dataforexport, file = "test1.txt", sep = "\t", row.names = FALSE)

我收到错误消息:

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
  cannot coerce class ""summary.pgls"" to a data.frame

我希望能够将分析结果保存到文本文件中,甚至是csv(理想情况下是附加文件,但这是另一个可能在其他地方得到解答的问题)< / p>

1 个答案:

答案 0 :(得分:2)

试一试 -

capture.output(summary(phylo.signal), file = "test1.txt")