我有6列的数据框架。第一个是实验对象的数据框架,第二个是实验区块的数据框架,而第3、4和5列是我要计算一个二进制分(0或1)的数值,我要在第六列中加上这个数值(这就是为什么现在它满是0)。
head(kfdblock3to9)
subject time gr ugr sdugr IL
40002.3 40002 3 0.4475618 0.3706000 0.02994533 0
40002.4 40002 4 0.4361786 0.3901111 0.01846110 0
40002.5 40002 5 0.4279880 0.4550000 0.02811839 0
40002.6 40002 6 0.4313647 0.4134444 0.04352974 0
40002.7 40002 7 0.4420889 0.4394286 0.02883143 0
40002.8 40002 8 0.4325227 0.3960000 0.06559222 0
I m trying to do this with a for loop, but I m a beginner in R and I m having difficulties with this. The scoring formula I m trying to implement is one where: If the value in column 3 ($gr) is less that the difference between the value in column 4 ($ugr) and .35 times the value in column 5 ($sdugr), then the subject receives a 1, otherwise a 0.
到目前为止,我试过的是:
for (i in kfdblock3to9$subject) {
if (kfdblock3to9$gr<(kfdblock3to9$ugr-(.35*kfdblock3to9$sdugr)))
kfdblock3to9$IL=1
else kfdblock3to9$IL=0
}
This gives me 50 warnings, all saying: "the condition has length > 1 and only the first element will be used"
我想我当时做错什么指数了,但我一直无法弄清楚,任何帮助都是感激不尽的。