I have a vector with ~5k observations, I'd like to group them in 4 categories, 4 if the observation<-2, 3 if [-2,0], 1 if (0,2], 2 if greater than 2. I'd like to have the corresponding group code in the same order as was encountered in the original vector. THIS IS NOT A HOMEWORK!
This is the code I have so far:
''for (i in newDailyDeltaScaled){
if (i<-2){
markovian.trial=c(markovian.trial,4)
}else if(-2<=i<=0){
markovian.trial=c(markovian.trial,3)
}else if(0<i<=2){
markovian.trial=c(markovian.trial,1)
}else{
markovian.trial=c(markovian.trial,2)
}
}
''
What am I doing wrong here?