Let's say I have sample data like this that is continuous d <- rnorm(100)
Now I want to have this variable stored in a set of levels that correspond to specific intervals. For example, anything >-1 would be level 1, -1 < x < 0 would be level 2 and so on.
I know we can create a new variable to store the levels, but is there any way of doing it without creating an additional variable of just the levels, thereby preserving the data i.e, factoring the variable based on a condition?
I want something looks like this
d
# [1] -0.129731527 0.832232654 -1.204235933 ...
str(d)
# Factor w/ n levels "1", "2" ...