I want to make various factor columns on my dataframe based on this column: (real file is large, is not ordered and values have more decimals)
> df
0.05
0.1
0.15
0.20
0.25
0.30
.
.
.
0.90
0.95
0.99
The values range from 0.05 to 0.99 and I want to make a factor columns in 0.1 and 0.05 bins and possibly others as well.
I tried using the ifelse
function like this:
df$bin1 <- ifelse(df$V1 < 0.1, 1 , ifelse(0.1 <= df$V1 & df$V1 < 0.2,2,ifelse(...))
It worked but the command was large and very cumbersome for the other bins that I want to use.