strsplit | R Documentation |
This functions uses strsplit
and adds the
possibility to split and keep the delimiter after or before the given split.
Or you can split between two given splits and keep both.
strsplit(x, split, type = "remove", perl = FALSE, ...)
x |
character vector, each element of which is to be split. Other inputs, including a factor, will give an error. |
split |
character vector (or object which can be coerced to such)
containing regular expression(s) (unless |
type |
a charachter. Either to |
perl |
logical. Should Perl-compatible regexps be used? Is |
... |
other inputs passed along to |
A list of the same length as x
, the i-th element of which contains
the vector of splits of x[i]
.
Jakob Gepp
strsplit
or
stackoverflow
for more details.
x <- c("3D/MON&SUN")
strsplit(x, "[/&]")
# [[1]]
# [1] "3D" "MON" "SUN"
strsplit(x, "[/&]", type = "before")
# [[1]]
# [1] "3D" "/MON" "&SUN"
strsplit(x, "[/&]", type = "after")
# [[1]]
# [1] "3D/" "MON&" "SUN"
x <- c("3D/MON&SUN 2D/MON&SUN")
strsplit(x, split("/", "M"))
# [[1]]
# [1] "3D" "MON&SUN 2D" "MON&SUN"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.