2017-10-28 6 views
0

から分割表:R:このサンプルデータを使用してDATAFRAME

statedf <- data.frame(state.x77) 
statedf$pop_class <- ifelse(statedf$Population > 10000, "so crowded!", 'where is everyone?') 
statedf$frost_class <- ifelse(statedf$Frost > 100, "crampons", "flipflops") 

がどのように私はこれらのバイナリ変数のすべての組み合わせの合計を示して2x2のテーブルを得ることができますか?たとえば、「混雑している」州はいくつですか? & "crampons"、 "とても混んでいる!" &「Tシャツ」、「どこにいるの?」 & "crampons"、 "どこにいるの?" &「Tシャツ」。

答えて

1

table functionを使用します。

table(statedf[,'pop_class'], statedf[,'frost_class']) 

組み合わせのテーブルを取得するには:

     crampons flipflops 
    so crowded!    3   3 
    where is everyone?  27  17 
関連する問題