Skip to contents

Group values with a difference between them being smaller than a user defined threshold. This function uses the groupSimilarityMatrix() function to create groups with smallest differences between its members. Differences between all members of one group are below the user defined threshold maxDiff. This is a more stringent grouping than what groupConsecutive() performs leading thus to smaller groups (with smaller differences between its members).

Usage

groupClosest(x, maxDiff = 1)

Arguments

x

numeric of values that should be grouped.

maxDiff

numeric(1) defining the threshold for difference between values in x to be grouped into the same group.

Value

integer with the group assignment (values grouped together have the same return value).

See also

Other grouping operations: groupConsecutive(), groupSimilarityMatrix()

Author

Johannes Rainer

Examples


x <- c(1.1, 1.9, 2.2)
groupClosest(x)
#> [1] 2 1 1
## Although the difference between the 1st and 2nd element would be smaller
## than the threshold, they are not grouped because the difference between
## the 2nd and 3rd element is even smaller. The first element is also not
## put into the same group, because it has a difference > diffRt to the 3rd
## element.

x <- c(1.1, 1.5, 1.7, 2.3, 2.7, 4.3, 4.4, 4.9, 5.2, 5.4, 5.8, 6, 7,
    9, 9.5, 15)

groupClosest(x)
#>  [1] 2 2 2 5 5 1 1 3 3 3 4 4 7 6 6 8