r - 来 self 的数据集的有条件分组的直方图

标签 r statistics grouping histogram

我当前的数据集 data.df来自大约 420 名学生,他们在 3 位讲师之一的指导下进行了 8 个问题的调查。 escore是我感兴趣的结果变量。


    'data.frame':   426 obs. of  10 variables:
     $ ques01: int  1 1 1 1 1 1 0 0 0 1 ...
     $ ques02: int  0 0 1 1 1 1 1 1 1 1 ...
     $ ques03: int  0 0 1 1 0 0 1 1 0 1 ...
     $ ques04: int  1 0 1 1 1 1 1 1 1 1 ...
     $ ques05: int  0 0 0 0 1 0 0 0 0 0 ...
     $ ques06: int  1 0 1 1 0 1 1 1 1 1 ...
     $ ques07: int  0 0 1 1 0 1 1 0 0 1 ...
     $ ques08: int  0 0 1 1 1 0 1 1 0 1 ...
     $ inst  : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
     $ escore: int  3 1 5 5 3 3 4 4 2 5 ...
     

我想知道如何生成 escore基于 inst 的值有条件地分离的直方图对于给定的观察。在我的脑海中,伪代码可能如下所示:

    par(mfrow=c(1,3)) 
    hist(escore, data.df$inst = 1)
    hist(escore, data.df$inst = 2)
    hist(escore, data.df$inst = 3)

但这当然行不通:-(

理想情况下,我的直方图如下所示:

3 separate histograms of ~140 observations each, grouped according to their "inst" value http://terpconnect.umd.edu/~briandk/escoreHistogramsbyInstructor-1.png

像往常一样,我觉得必须有一种简单的方法来做到这一点。在任何“条件/分组”意义上,我都可以从我的数据中提取这些图形,我假设它是 得到 可概括为您想要根据某些条件制作的各种图。

另外,如果之前已经回答过这个问题,我真的很抱歉。我的主要困难在于弄清楚如何以有意义的方式提出问题。

在此先感谢您的帮助!

最佳答案

使用格子包:

library(lattice)
histogram( ~ escore | inst, data=X)

如果 X是你的 data.frame 对象。

关于r - 来 self 的数据集的有条件分组的直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1521390/

相关文章:

ruby-on-rails - 如何使用 Redis 跟踪每日和每周的活跃用户?

MySQL 从数据库分组

php - 在循环中获取数组的增量

r - R中多列的密集排名

r - 如何确保两层 geom_point 正确对齐?

java - java中的随机标识符

math - 如何获得趋势的标准化斜率

c# - 对排序列表进行分组而不影响 linq 中的排序

r - 合并行连接由逗号-R 编程分隔的列之一中的内容

r - 如何获得两个日期字符串之间的差异(以分钟为单位)?