pairwise: Reorder Strings So That Matching Strings are Neighbours

View source: R/string.R

pairwiseR Documentation

Reorder Strings So That Matching Strings are Neighbours

Description

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_"))

# Use default starts resulting from splitting at a split character
pairwise(x, split = "_")

# This is actually the default
pairwise(x)

# 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 = "[.]")

# Same result as in the first example
pairwise(x, split = "[._]")


KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.