Iterating through vector in R: replacement has length zero
===

I am trying to iterate through a vector and edit a new one however I keep getting the error replacement has length zero. The portion where the error occurs is here:


    NewPos1 = rep(NROW(sig_decision))
    for( i in 2:length(NewPos)){
     NewPos1[i] = ifelse( NewPos[i] == 0 & NewPos[i-1] == 1 & ind1[i] > 0 , 1, ifelse(NewPos[i] ==0 & NewPos[i-1] == -1 & ind1[i] < 0  , -1,0))}

Where am I going wrong?