R:来自Dataframe的列联表

时间:2017-10-28 04:37:56

标签: r

使用此样本数据:

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表?例如,有多少州是如此拥挤!&#34; &安培; &#34;冰爪&#34;,&#34;如此拥挤!&#34; &安培; &#34; T恤&#34;,&#39;每个人都在哪里?&#39; &安培; &#34;冰爪&#34;,&#39;每个人都在哪里?&#39; &安培; &#34; T恤&#34;

1 个答案:

答案 0 :(得分:1)

使用table function

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

获取组合表:

                     crampons flipflops
  so crowded!               3         3
  where is everyone?       27        17