从NbClust中检索最佳数量的集群

时间:2016-05-18 07:27:27

标签: r console console-output

R中的许多函数提供某种控制台输出(例如NbClust()等。)是否有任何方法可以检索某些输出(例如某个整数值)而无需查看输出?从控制台读取的任何方式?

想象一下,输出看起来像package manual中提供的示例代码的以下输出:

[1] "Frey index : No clustering structure in this data set"
*** : The Hubert index is a graphical method of determining the number of clusters.
                In the plot of Hubert index, we seek a significant knee that corresponds to a 
                significant increase of the value of the measure i.e the significant peak in Hubert
                index second differences plot. 

*** : The D index is a graphical method of determining the number of clusters. 
                In the plot of D index, we seek a significant knee (the significant peak in Dindex
                second differences plot) that corresponds to a significant increase of the value of
                the measure. 

******************************************************************* 
* Among all indices:                                                
* 1 proposed 2 as the best number of clusters 
* 2 proposed 4 as the best number of clusters 
* 2 proposed 6 as the best number of clusters 
* 1 proposed 7 as the best number of clusters 

                   ***** Conclusion *****                            

* According to the majority rule, the best number of clusters is  4 


*******************************************************************

如何从上述输出的最后一行检索 4 值?

2 个答案:

答案 0 :(得分:3)

最好使用对象而不是在控制台中输出。任何" good" 函数都会返回希望结构化的输出,可以使用$@符号进行访问,使用str()查看对象&# 39; s结构。

在您的情况下,我认为这应该有效:

length(unique(res$Best.partition))

答案 1 :(得分:0)

另一个选择是:

<form onsubmit="event.preventDefault();">
</form>