GRS - 11 months ago 79
R Question

# How to use as.numeric to transform a vector of random numbers into a vector of 0,1,2?

Let's say I have a vector $(0,1,2,3,4,5)$.
I want to transform it into the following: if the value in the original vector is:

$=0 \rightarrow 0$

$> 0$ but $<5 \rightarrow 1$

$=5 \rightarrow 2$

I tried:

v <- c(0,1,2,3,4,5)
v <- as.numeric(v=0, v>0 & v<5, v=5)