I have a very strange thing happening in R. This code gives the following error, "Error in 1 && CurrentData$phase[i] > -0.5 || PriorData$phase[MatchTimeFrames(i, : target of assignment expands to non-language object"
return (CurrentData$phase[i-1]<-1 && CurrentData$phase[i]>-0.5 ||
PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)-1]<-1 &&
PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)] > -0.5 ||
CurrentData$phase[i]>0 ||
PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)] >0
)
If I comment out the first condition, the code runs.
return (#CurrentData$phase[i-1]<-1 && CurrentData$phase[i]>-0.5 ||
PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)-1]<-1 &&
PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)] > -0.5 ||
CurrentData$phase[i]>0 ||
PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)] >0
)
If I comment out the second condition, the code runs.
return (CurrentData$phase[i-1]<-1 && CurrentData$phase[i]>-0.5 ||
#PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)-1]<-1 &&
PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)] > -0.5 ||
CurrentData$phase[i]>0 ||
PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)] >0
)
Obviously, I want both conditions to run and what made it work was putting a space between the less than sign and the -1 on the second condition.
return (CurrentData$phase[i-1]<-1 && CurrentData$phase[i]>-0.5 ||
PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)-1]< -1 && PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)] > -0.5 ||
CurrentData$phase[i]>0 ||
PriorData$phase[MatchTimeFrames(i, CurrentData, PriorData)] >0
)
Any idea why that is happening? It seems very strange that in this particular instance R is requiring a space between the less than sign and -1. Notice that the first term, CurrentData$phase[i-1]<-1, has no space.
Thank you.