Though I believe that r2evans is right, here it goes. Note that in the test example I have left the output of cut
untouched.
newLabels <- function(x, dig.lab = 4){
lev <- levels(x)
pattern <- paste0("^[\\(\\[][-]*\\d*\\.\\d{",
dig.lab,
"}|,[-]*\\d*\\.\\d{",
dig.lab,
"}"
)
m <- gregexpr(pattern = pattern, levels(x))
y <- regmatches(lev, m)
y <- sapply(y, paste, collapse = "")
y <- paste0(y, substring(lev, nchar(lev)))
y
}
set.seed(1234)
x <- runif(1000, 0, 6e6)
y <- cut(x, breaks = 10, dig.lab = 20)
z <- factor(y, labels = newLabels(y, dig.lab = 4))
levels(z)
#[1] "(-3942.8915,601427.6033]" "(601427.6033,1200804.3310]"
#[3] "(1200804.3310,1800181.0587]" "(1800181.0587,2399557.7864]"
#[5] "(2399557.7864,2998934.5141]" "(2998934.5141,3598311.2418]"
#[7] "(3598311.2418,4197687.9694]" "(4197687.9694,4797064.6971]"
#[9] "(4797064.6971,5396441.4248]" "(5396441.4248,6001811.9198]"