对于仅控制台输出,请阅读问题注释中的 @EliBerkow 链接。对于表输出或在函数中使用,可以使用formatC()
。
示例
(output <- summary(glm(I(Sepal.Length > 5.7) ~ Sepal.Width + Species,iris,family=binomial()))$coefficients)
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) -15.846295 3.893382 -4.070059 4.700128e-05
# Sepal.Width 3.274112 0.970872 3.372342 7.453193e-04
# Speciesversicolor 7.149531 1.533740 4.661501 3.139108e-06
# Speciesvirginica 9.283911 1.630188 5.694992 1.233776e-08
全部为四位数:
as.data.frame(apply(output,2,formatC,format="f",digits=4))
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) -15.8463 3.8934 -4.0701 0.0000
# Sepal.Width 3.2741 0.9709 3.3723 0.0007
# Speciesversicolor 7.1495 1.5337 4.6615 0.0000
# Speciesvirginica 9.2839 1.6302 5.6950 0.0000
不同位数:
setNames(data.frame(output[,-4],formatC(output[,4],digits=4)),colnames(output))
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) -15.846295 3.893382 -4.070059 0.0000
# Sepal.Width 3.274112 0.970872 3.372342 0.0007
# Speciesversicolor 7.149531 1.533740 4.661501 0.0000
# Speciesvirginica 9.283911 1.630188 5.694992 0.0000
本文链接:https://www.f2er.com/3159811.html