string.split | R Documentation |
Splits a string based on a separator and returns either a specific position or the last element of the resulting vector.
string.split(string, sep, position)
string |
A character vector (or object that can be coerced to character) |
sep |
The separator to use for splitting the string |
position |
Numeric value indicating which element to extract after splitting. If not provided or non-numeric, returns the last element |
The function first ensures the input is a character vector, then splits it using the provided separator. If a numeric position is specified, it extracts that element from each split result. If no position is specified or the position is non-numeric, it returns the last element of each split result.
A character vector containing the extracted elements
string.split("hello.world", ".", 1) # Returns "hello"
string.split("hello.world", ".", 2) # Returns "world"
string.split("hello.world.test", ".") # Returns "test"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.