【问题标题】:histogram based on counts of one variable with intervals of numerical variable基于具有数值变量区间的一个变量的计数的直方图
【发布时间】:2015-05-29 02:27:08
【问题描述】:

我正在尝试创建 dengue=1 的计数直方图,x 轴是 age.cut 变量。

 dengue age  sex    net sector ageHalf  age.cut
1   0   16  female  no  sector1 0      (15,20]
2   0   33  male    no  sector1 0      (30,35]
3   0   1   male    no  sector1 0      [0,5]
4   0   35  male    no  sector1 0      (30,35]
5   0   6   male    no  sector1 0      (5,10]
6   0   27  female  no  sector2 0      (25,30]
7   0   6   male    no  sector2 0      (5,10]

作为 r 的新手,我不太确定如何获取直方图来绘制正确的信息。我将年龄变量分成 5 个间隔。

我创建了一个数据框,其中仅包含 dengue=1 和 age.cut 间隔,但之后甚至不知道从哪里开始。

df<-dengue[index, c(1,7)]

基本上我只想得到一个直方图,它给出每个区间的总计数并将它们放在条形图中——以查看分布。

谢谢!

康纳

【问题讨论】:

    标签: r


    【解决方案1】:

    您不能使用 hist,而不是手动创建剪辑:

    hh = hist(df[,"age"], breaks=seq(5,50,by=5))
    

    之后检查 hh。并且只过滤 dengue == 1 - 可能从 dplyr 包中过滤:

    df1 = dplyr::filter(df, dengue == 1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      相关资源
      最近更新 更多