2016-07-08 79 views
0

我已經通過去除數據從2類派生的新數據幀major.groups從現有的數據幀antiques顯示我滴加類別盒我用boxplot(),BoxesMetalware仍然出現在x軸上(顯然沒有相應的數據)。()仍然刪去相應的行

如何在使用新數據幀major.groups時排除這些問題?我顯然可以將它們從R以外的地方移除並重新導入 - 但我確定必須有更好的方法。

非常感謝提前。

回答

0

沒有可重複的例子,我無法測試這個。但是,這應該工作:

major.groups <- droplevels(antiques[antiques$Group!="Boxes" & antiques$Group!="Metalware",]) 

注意,對於所有現有的因子水平boxplot()顯示值:

If multiple groups are supplied either as multiple arguments or 
via a formula, parallel boxplots will be plotted, in the order of 
the arguments or the order of the levels of the factor (see 
‘factor’). 

對於一個因素,下降值並不意味着下降的水平。試試這個:

x <- factor(letters[1:4]) 
#[1] a b c d 
#Levels: a b c d 
x[-1] 
#[1] b c d 
#Levels: a b c d 
droplevels(x[-1]) 
#[1] b c d 
#Levels: b c d 
相關問題