2013-06-30 20 views
2

faithfulr中的內置數據集。以編程方式查找爆發最多的子區間

我必須計算爆發最多的子區間。

我已經通過下面的方式試了一下:

vct <- faithful$eruptions 
range(vct) 
vct.cut <- cut(vct,seq(1.5,5.5,by=0.5),right=FALSE) 
freq <- table(vct.cut) 

    y <- sort(freq,decreasing=TRUE) 

#the sub-interval that has the most eruptions. 
    y[1] 

的程序是正確的嗎?我正在尋找一種更好的方式來以編程方式查找爆發最多的子區間。

回答

3

您正在尋找which.max

names(freq)[which.max(freq)] 
相關問題