私はベクトルを持っていますx<-rnorm(100)
次の条件を適用したいと思います。
if any element of x is larger than 2 -> 1.
if any element of x is smaller than -2 -> -1.
otherwise keep x.
私は試した:
ifelse(x>2,1, ifelse(x<-2,-1),x))
しかし、これはうまくいかないようです。私は何を間違っていますか?
私はベクトルを持っていますx<-rnorm(100)
次の条件を適用したいと思います。
if any element of x is larger than 2 -> 1.
if any element of x is smaller than -2 -> -1.
otherwise keep x.
私は試した:
ifelse(x>2,1, ifelse(x<-2,-1),x))
しかし、これはうまくいかないようです。私は何を間違っていますか?