This is a reproducible example:
I want to see if tac2 is less than 80% tac and if it is, then cap the decrease at 80% of tac.
Error in if ((tac2[i] - tac) < tac * 0.8) { : missing value where TRUE/FALSE needed_
tac = 1000
tac2= c(790,600,678,900,1200,300,800,9000)
R
for (i in tac2) {
if ((tac2[i]-tac) < tac*.8) {
tac2[i] <- tac - tac*.2
} else {
tac2[i] = tac2[i]
print(tac2)
}
}