Learn R Programming

broadcast (version 0.1.7)

bc.str: Broadcasted String Operations

Description

The bc.str() function performs broadcasted string operations on pairs of arrays.

Usage

bc.str(x, y, op, ...)

# S4 method for ANY bc.str(x, y, op)

Value

For concatenation operation:

A character array as a result of the broadcasted concatenation operation.


For relational operation:

A logical array as a result of the broadcasted relational comparison.


For distance operation:

An integer array as a result of the broadcasted distance measurement.


Arguments

x, y

conformable vectors/arrays of type character.

op

a single string, giving the operator.
Supported concatenation operators: +.
Supported relational operators: ==, !=.
Supported distance operators: levenshtein.

...

further arguments passed to or from methods.

References

The 'C++' code for the Levenshtein edit string distance is based on the code found in https://rosettacode.org/wiki/Levenshtein_distance#C++

See Also

broadcast_operators

Examples

Run this code

# string concatenation:
x <- array(letters, c(10, 2, 1))
y <- array(letters, c(10,1,1))
bc.str(x, y, "+")


# string (in)equality:
bc.str(array(letters), array(letters), "==")
bc.str(array(letters), array(letters), "!=")


# string distance (Levenshtein):
x <- array(month.name, c(12, 1))
y <- array(month.abb, c(1, 12))
out <- bc.str(x, y, "levenshtein")
dimnames(out) <- list(month.name, month.abb)
print(out)

Run the code above in your browser using DataLab