Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Conditional Flow in R? [closed]

$
0
0

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?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>