Skip to contents

Reorder strings so that strings that start with the same characters appear next to each other

Usage

pairwise(x, starts = defaultStarts(x, split), split = "_")

Arguments

x

vector of character

starts

vector of character defining the start strings that are looked for in x to find strings that belong together. The default is to take the unique strings appearing before a split character (if any)

split

split character used to create default start strings

Examples

x <- c("a.1", "b_hi", "c", "a.2", "d", "b_bye")

# You have the most control when setting the starts argument
pairwise(x, starts = c("a.", "b_"))
#> [1] "a.1"   "a.2"   "b_hi"  "b_bye" "c"     "d"    

# Use default starts resulting from splitting at a split character
pairwise(x, split = "_")
#> [1] "a.1"   "b_hi"  "b_bye" "c"     "a.2"   "d"    

# This is actually the default
pairwise(x)
#> [1] "a.1"   "b_hi"  "b_bye" "c"     "a.2"   "d"    

# Note that the split parameter is interpreted as a pattern where the
# dot has a special meaning unless it is escaped or enclosed in []
pairwise(x, split = "[.]")
#> [1] "a.1"   "a.2"   "b_hi"  "c"     "d"     "b_bye"

# Same result as in the first example
pairwise(x, split = "[._]")
#> [1] "a.1"   "a.2"   "b_hi"  "b_bye" "c"     "d"