没有匹配调用的R函数摘要

时间:2014-07-21 17:18:36

标签: r function

我想知道是否有可能只在Call:函数中显示R公式。

require(graphics)

## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
## Page 9: Plant Weight Data.
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
summary(lm.D9)

输出

Call:
lm(formula = weight ~ group)

Residuals:
    Min      1Q  Median      3Q     Max
-1.0710 -0.4938  0.0685  0.2462  1.3690

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   5.0320     0.2202  22.850 9.55e-15 ***
groupTrt     -0.3710     0.3114  -1.191    0.249
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.6964 on 18 degrees of freedom
Multiple R-squared:  0.07308,   Adjusted R-squared:  0.02158
F-statistic: 1.419 on 1 and 18 DF,  p-value: 0.249

1 个答案:

答案 0 :(得分:4)

你可以尝试

ss <- capture.output(summary(lm.D9))
cat(ss[-(1:3)],sep="\n")

(更一般地说,您可以尝试使用grep()&#34; [Cc] all&#34;在输出中做一些奇特的事情,并排除该行和后续行......)否则,您将&#39; d必须破解stats:::print.summary.lm,例如

pp <- stats:::print.summary.lm
body(pp) <- body(pp)[-2]
pp(summary(lm.D9))
print.summary.lm <- pp
summary(lm.D9)

(请注意,这是相当脆弱的;它取决于Call:打印是函数体的第一行,并且该行中没有任何内容对函数的其余部分是必需的。)