R Error in cut.default : ‘breaks’ are not unique (2 Examples)

This article illustrates how to deal with the “Error in cut.default : ‘breaks’ are not unique” in R.

Construction of Example Data

data(iris)                                               # Loading example data
head(iris)
#   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 1          5.1         3.5          1.4         0.2  setosa
# 2          4.9         3.0          1.4         0.2  setosa
# 3          4.7         3.2          1.3         0.2  setosa
# 4          4.6         3.1          1.5         0.2  setosa
# 5          5.0         3.6          1.4         0.2  setosa
# 6          5.4         3.9          1.7         0.4  setosa

Example 1: Replicating the Error Message in cut.default : ‘breaks’ are not unique

cut(iris$Sepal.Length, breaks = c(- Inf, 3, 3, 5, Inf))  # Non-unique breaks
# Error in cut.default(x, breaks = c(0, 1, 1, 2, 10)) : 
#   'breaks' are not unique

Example 2: Solving the Error Message in cut.default : ‘breaks’ are not unique

cut(iris$Sepal.Length, breaks = c(- Inf, 3, 5, Inf))     # Unique breaks
#   [1] (5, Inf] (3,5]    (3,5]    (3,5]    (3,5]    (5, Inf] (3,5]    (3,5]   
#   [9] (3,5]    (3,5]    (5, Inf] (3,5]    (3,5]    (3,5]    (5, Inf] (5, Inf]
#  [17] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (3,5]    (5, Inf]
#  [25] (3,5]    (3,5]    (3,5]    (5, Inf] (5, Inf] (3,5]    (3,5]    (5, Inf]
#  [33] (5, Inf] (5, Inf] (3,5]    (3,5]    (5, Inf] (3,5]    (3,5]    (5, Inf]
#  [41] (3,5]    (3,5]    (3,5]    (3,5]    (5, Inf] (3,5]    (5, Inf] (3,5]   
#  [49] (5, Inf] (3,5]    (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
#  [57] (5, Inf] (3,5]    (5, Inf] (5, Inf] (3,5]    (5, Inf] (5, Inf] (5, Inf]
#  [65] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
#  [73] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
#  [81] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
#  [89] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (3,5]    (5, Inf] (5, Inf]
#  [97] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
# [105] (5, Inf] (5, Inf] (3,5]    (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
# [113] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
# [121] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
# [129] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
# [137] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
# [145] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf] (5, Inf]
# Levels: (-Inf,3] (3,5] (5, Inf]

Related Articles & Further Resources

Below, you can find some further resources on topics such as extracting data, data objects, and ggplot2.

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top