I am not sure I quite understand how to use an if and else statement within a for loop. My code looks like this:
> X
[1] 1 0 1 1 1
A=0
for (i in 1:5){
if (X[i]=1)
A=A+1
}
else{
A=A
}
for example in this case there are 4 '1's in the vector X. So for every 1 in the vector I want it to add 1 to the value of A. (So A should equal 4).