首页 > 解决方案 > cat 函数中的 R 汇总函数导致问题

问题描述

我无法将带有 cat 函数的线性回归模型的摘要打印到文本文件中。产生错误的代码行

cat(summary(model), file = "results.txt", sep = "\n")

此行产生错误:

argument 1 (type 'list') cannot be handled by 'cat'

我想不出办法来解决这个问题。这是什么原因造成的?

标签: r

解决方案


Here is a capture.output solution.

model <- lm(Sepal.Length ~ Sepal.Width, iris)
capture.output(summary(model), file = "results.txt")

推荐阅读