双向表中的条件

时间:2014-03-23 10:56:44

标签: r

我有以下数据

LOGIN,IMPROVE,EXECNUMBER,RESULT
1002,NO,1,0
1002,NO,2,0
1002,NO,3,0
1002,NO,4,0
1002,NO,5,0
1002,NO,6,0
1002,NO,7,0
1002,NO,8,0
1002,NO,9,0
1002,NO,10,0
1002,NO,11,0
1002,NO,12,26
1002,NO,13,61
1002,NO,14,29
1002,NO,15,30
1002,NO,16,36
1002,NO,17,44
1002,NO,18,36
1002,NO,19,33
1002,NO,20,39
1002,NO,21,44
1002,NO,22,40
1002,NO,23,57
1002,NO,24,61
1002,NO,25,57
1002,NO,26,29
1002,NO,27,33
1002,NO,28,61
1002,NO,29,57
1002,NO,30,30
1002,NO,31,53
1002,NO,32,33
1002,NO,33,53
1002,NO,34,40
1002,NO,35,53
1002,NO,36,45
1002,NO,37,57
1002,NO,38,51
1002,NO,39,47
1002,NO,40,47
1002,NO,41,57
1002,NO,42,43
1002,NO,43,0
1002,NO,44,40
1002,NO,45,66
1002,NO,46,27
1002,NO,47,35
1002,NO,48,61
1002,NO,49,22
1002,NO,50,34
1002,NO,51,61
1002,NO,52,50
1002,NO,53,60
1002,NO,54,40
1002,NO,55,34
1002,NO,56,28
1002,NO,57,39
1002,NO,58,32
1003,YES,1,0
1003,YES,2,0
1004,YES,1,0
1004,YES,2,0
1004,YES,3,0
1004,YES,4,0
1006,YES,1,0
1006,YES,2,0
1006,YES,3,0
1006,YES,4,0
1006,YES,5,0
1006,YES,6,0
1006,YES,7,0
1006,YES,8,0
1006,YES,9,0
1007,NO,1,0
1007,NO,2,0
1007,NO,3,0
1007,NO,4,0
1007,NO,5,0
1007,NO,6,0
1007,NO,7,0
1007,NO,8,0
1007,NO,9,0
1007,NO,10,0
1008,YES,1,0
1008,YES,2,0
1008,YES,3,0
1008,YES,4,0
1008,YES,5,0
1012,YES,1,0
1013,YES,1,4
1013,YES,2,34
1013,YES,3,34
1013,YES,4,30
1013,YES,5,50
1013,YES,6,23
1013,YES,7,42
1013,YES,8,36
1013,YES,9,50
1013,YES,10,20
1013,YES,11,57
1013,YES,12,32
1013,YES,13,47
1013,YES,14,57
1013,YES,15,50
1013,YES,16,30
1014,YES,1,0
1014,YES,2,0
1014,YES,3,0
1014,YES,4,0
1014,YES,5,0
1014,YES,6,0
1014,YES,7,0
1014,YES,8,0
1014,YES,9,0
1014,YES,10,0
1014,YES,11,0
1014,YES,12,0
1014,YES,13,0
1014,YES,14,34
1014,YES,15,57
1014,YES,16,36
1014,YES,17,0
1015,NO,1,0
1015,NO,2,0
1015,NO,3,0
1015,NO,4,0
1015,NO,5,0
1015,NO,6,0
1015,NO,7,0
1015,NO,8,0
1015,NO,9,0
1015,NO,10,0
1015,NO,11,25
1015,NO,12,21
1015,NO,13,33
1015,NO,14,29
1015,NO,15,25
1015,NO,16,40
1015,NO,17,36
1015,NO,18,28
1015,NO,19,47
1015,NO,20,44
1015,NO,21,29
1015,NO,22,19
1015,NO,23,8
1015,NO,24,28
1015,NO,25,47
1015,NO,26,29
1015,NO,27,32
1015,NO,28,16
1015,NO,29,28
1015,NO,30,18
1015,NO,31,36
1015,NO,32,13
1015,NO,33,47
1015,NO,34,27
1016,NO,1,0
1016,NO,2,0
1016,NO,3,0
1016,NO,4,0
1016,NO,5,0
1016,NO,6,0
1016,NO,7,0
1016,NO,8,0
1016,NO,9,0
1016,NO,10,0
1016,NO,11,0
1016,NO,12,0
1016,NO,13,0
1016,NO,14,0
1016,NO,15,0
1016,NO,16,0
1016,NO,17,0
1016,NO,18,0
1016,NO,19,26
1016,NO,20,21
1016,NO,21,22
1016,NO,22,21
1016,NO,23,28
1016,NO,24,30
1016,NO,25,20

描述参与者执行练习并在执行后改进。 LOGIN是参与者标识符,IMPROVE显示参与者是否改进,RESULT范围从0到66并且是每次执行的结果,EXECNUMBER是练习的执行编号(意味着第一次执行,第二次执行等)。

我需要在X exe(0到66)中建立一个带有RESULT的交叉表,在Y exe(从1到58)上用EXECNUMBER构建一个交叉表,我用这个代码做了

> myData <- read.csv(file='data.csv',sep=',',header=T)
> res <- table(myData$EXECNUMBER,myData$RESULT)

但现在我被要求用IMPROVE = YES

的人填充表格

存在: n每个执行号码和每个结果的参与者数量。 m每个执行号码和每个结果的参与者数量,IMPROVE = YES

我需要用m / n填充表格

1 个答案:

答案 0 :(得分:0)

查看subset函数(?subset)。

myDataSubsetYes <- subset(myData, myData$IMPROVE == "SI")
table(myDataSubsetYes$EXECNUMBER, myDataSubsetYes$RESULT)

(顺便说一句:IMPROVE栏中没有“是”)