halveString {eatTools} | R Documentation |
Split string exactly in two parts
Description
strsplit
splits a string according to a specific regular expression. The number
of occurrences of the splitting regular expression defines the number of splits. halveString
allows to split the string in only two parts, no matter how often the splitting regular expression occurs.
Usage
halveString (string, pattern, first = TRUE , colnames=c("X1", "X2"))
Arguments
string |
A character vector. |
pattern |
character vector (or object which can be coerced to such) to use for splitting. |
first |
Logical: Relevant if the pattern occurs more than one time in the string. Defines whether the first (default) or last occurrence is used for splitting. |
colnames |
Optional: character vector of length 2 to specify the colnames of the resulting data.frame. |
Value
A matrix with two columns
Examples
str1 <- c("John_Bolton", "Richard_Milhouse_Nixon", "Madonna")
strsplit(str1, split = "_")
halveString(str1, pattern = "_")
halveString(str1, pattern = "_", first=FALSE)
# split patterns with more than one character and regular expression
str2 <- c("John._.Bolton", "Richard._.Milhouse._.Nixon", "Madonna")
halveString(str2, pattern = encodeString("._."), first=FALSE)
[Package eatTools version 0.7.6 Index]