I am trying to apply an if condition to each element of vectors in R, but seems that I am doing something wrong:
nobjects <- length(EMATRSTDV)
for (i in 1:nobjects) {
if (MPEMAPlusDemiTR - EMATRSTDV > Cl(myData$AAPL)){
ShortLevel <- MPEMAPlusDemiTR - EMATRSTDV
} else {
ShortLevel <- "..."
}
}
I am getting the error message:
Error in if (MPEMAPlusDemiTR - EMATRSTDV > Cl(myData$AAPL)) { : missing value where TRUE/FALSE needed In addition: Warning message: In if (MPEMAPlusDemiTR - EMATRSTDV > Cl(myData$AAPL)) { : the condition has length > 1 and only the first element will be used