I have a dataframe:
a <- matrix(c(1,2,3,4), 2,2)
colnames(a) <- c(\"a\", \"b\")
df <- as.data.frame(a)
> df
a b
1 1 3
2 2 4
Fir
The two values are not in range. You can circumvent this by making another break. I chose Inf
, you can use a finite value.
cat.b <- cut(df$b, c(-Inf, quantile(df$a), Inf))
#next line can be done better, but illustrates the purpose
levels(cat.b)[length(levels(cat.b))] <- ">2"
levels(cat.b)[1] <- "<1"
cat.b
[1] >2 >2
Levels: (1,1.25] (1.25,1.5] (1.5,1.75] (1.75,2] >2