r - split the data in queal ranges

# Step 1: Create a dataset (replace this with your actual dataset)
set.seed(123)
data <- data.frame(value = rnorm(100))

# Step 2: Specify the number of desired ranges
num_ranges <- 5

# Step 3: Calculate range boundaries
range_boundaries <- quantile(data$value, probs = seq(0, 1, length.out = num_ranges + 1))

# Step 4: Create a new variable indicating the range for each observation
data$range <- cut(data$value, breaks = range_boundaries, include.lowest = TRUE, labels = FALSE)

# Step 5: Display the results
head(data)