I'm currently trying to neatly cut data with use of the Hmisc
package, as in the example below:
dummy <- data.frame(important_variable=seq(1:1000))
require(Hmisc)
dummy$cuts <- cut2(dummy$important_variable, g = 4)
The produced cuts are correct with respect to the values:
important_variable cuts
1 1 [ 1, 251)
2 2 [ 1, 251)
3 3 [ 1, 251)
4 4 [ 1, 251)
5 5 [ 1, 251)
6 6 [ 1, 251)
> table(dummy$cuts)
[ 1, 251) [251, 501) [501, 751) [751,1000]
250 250 250 250
However, I would like for the data to be presented slightly differently. For instance instead of
[ 1, 251 )
[ 251, 501 )
I would prefer the notation
1 - 250
251 - 500
As I'm doing a lot of that on multiple variables I'm interested in a reproducible solution that would be easy to apply across multiple variables.
Edit
Following the discussion in comments, the solution would have to work on more messy variables, like x2 <- runif(100, 5.0, 7.5)
.