[英]Evaluation of values and an OR statement in R
As part of an R
program I create matrices patients, invited
and missinrow
and scalars numdrop
and maxses
. 作为一个的一部分
R
程序创建矩阵的患者, invited
和missinrow
和标量numdrop
和maxses
。 These all exist and are properly created. 这些都存在并正确创建。
I then try this line 然后我尝试这条线
else if (invited[iPatient, iSession] >= maxses |
missinrow[iPatient,iSession] >= (numdrop+1 )) {
patients[iPatient,iSession] <- 'D'}
The part before the |
|
前的部分 works perfectly, the part after the |
完美地工作,
|
之后的部分 doesn't seem to do anything at all. 似乎什么也没做。
I've tried making this line into two statements, I've tried ||
我试过将这行变成两个语句,我试过
||
instead of |
代替
|
, I've stared at it for hours. ,我已经盯着它看了几个小时。
Help! 救命! Thanks
谢谢
Added 6/28/11 The program reads parameters from another file and creates data. 已添加11/6/28程序从另一个文件读取参数并创建数据。 But here is some output:
但是这是一些输出:
invited[1:5, 1:14]
gives 给
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,] 0 1 2 3 4 5 6 7 8 9 10 11 12 12
[2,] 0 1 2 3 4 5 6 7 8 9 10 11 12 12
[3,] 0 1 2 3 4 5 6 7 8 9 10 11 12 12
[4,] 0 0 0 1 2 3 4 5 6 7 8 9 10 11
[5,] 0 0 0 1 2 3 4 5 6 7 8 9 10 11
which is fine 很好
missinrow[1:5, 1:14]
gives 给
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,] 1 2 3 4 5 6 7 8 9 10 0 0 0 0
[2,] 1 2 3 4 5 6 7 8 9 10 0 0 0 0
[3,] 1 2 3 4 5 0 0 0 0 0 0 1 0 0
[4,] 0 0 1 2 0 0 1 2 3 4 5 6 7 0
[5,] 0 0 1 2 3 4 5 6 7 8 9 10 11 12
also fine, but 还可以,但是
patients[1:5, 1:14]
gives 给
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,] "S" "S" "S" "S" "S" "S" "S" "S" "S" "S" "A" "S" "D" "D"
[2,] "S" "S" "S" "S" "S" "S" "S" "S" "S" "S" "A" "A" "D" "D"
[3,] "S" "S" "S" "S" "S" "A" "S" "A" "A" "A" "S" "S" "D" "D"
[4,] "NA" "W" "S" "S" "A" "S" "S" "S" "S" "S" "S" "S" "S" "A"
[5,] "NA" "W" "S" "S" "S" "S" "S" "S" "S" "S" "S" "S" "S" "S"
and we see that the cells where invited
is higher than maxses
(which is 12) are all D
, as they should be, but those where missinrow
is higher than numdrop + 1
(which is 4 +1) are not D
. 并且我们看到,被
invited
高于maxses
(为12)的像元应该都是D
,但是那些未missinrow
高于numdrop + 1
(是4 + 1)的像元不是D
Here is some code including your expression 这是一些代码,包括您的表情
invited <- 10 * matrix(12:1, nrow=3)
missinrow <- matrix(1:12, nrow=3)
patients <- matrix(rep("A",12), nrow=3)
maxses <- 100
numdrop <- 7
for (iPatient in 1:3) {
for (iSession in 1:4) {
if (iPatient==iSession) { patients[iPatient,iSession] <- 'B'}
else if (invited[iPatient, iSession] >= maxses |
missinrow[iPatient,iSession] >= (numdrop+1 )) {
patients[iPatient,iSession] <- 'D'}
}
}
Looking at the three matrices 看三个矩阵
> invited
[,1] [,2] [,3] [,4]
[1,] 120 90 60 30
[2,] 110 80 50 20
[3,] 100 70 40 10
> missinrow
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
> patients
[,1] [,2] [,3] [,4]
[1,] "B" "A" "A" "D"
[2,] "D" "B" "D" "D"
[3,] "D" "A" "B" "D"
I would say the else if
statement was working as expected, and that the "D"s on the left hand side of patients
corresponded to the second else if
condition. 我会说
else if
语句按预期工作,并且patients
左侧的“ D”对应于else if
条件的第二个else if
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.