我对R编程还很陌生,并且一直在努力理解某些对象似乎如何将变量传递给函数,但是似乎并没有公开地返回这些变量。看一下这个例子:
install.packages("cluster")
library(cluster)
x <- rbind(cbind(rnorm(10, 0, 0.5), rnorm(10, 0, 0.5)),
cbind(rnorm(15, 5, 0.5), rnorm(15, 5, 0.5)),
cbind(rnorm( 3,3.2,0.5), rnorm( 3,3.2,0.5)))
fannyx <- cluster::fanny(x, 2)
p <- cluster::clusplot(fannyx)
检查图时,将提供以下信息:
These two components explain 100 % of the point variability
我根本不明白这些信息是如何传递的!fannyx
-object不返回解释的可变性。
当其他功能summary()
通过使用而不是提供更多信息时,我就遇到了此问题print()
。
如何解释呢?
如果我们扩展clusplot
功能
cluster:::clusplot.default
我们可以看到以下代码行:
sub = paste("These two components explain",
round(100 * var.dec, digits = 2), "% of the point variability.")
因此,在这种情况下,该特定指标是在函数内部进行计算的,然后添加到绘图中。
编辑:
我们可以看到cluster:::mkCheckX
return var.dec
,这称为clusplot
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句