Description Usage Arguments Details Value Author(s) Examples
Extract only part of a string, given a separator
1 | subsetString(string, sep = " ", position = 3, flexible = FALSE)
|
string |
a vector of strings |
sep |
the separator that separates the parts of the strings |
position |
the position of the element you wish to extract |
flexible |
Force the function to find the string "sep"? See details |
Given a string with a separator (e.g., "Subject 001", where the separator is a space), this function can be used to extract only whatever follows the separator (in this case, "001"). It is often used when data comes in with a conglomorated identifier (such as case-matchNumber-drawNumber-Month).
The "flexible" function is for instances where a particular string (i.e., sep
) is found in only some elements of string
. For example,
if the string is c("...call..ID", "...call..Gender", "ethnicity"), if flexible
is false, it will search for the string "...call.." in the string "ethnicity", and, not
finding it, will return NA. To overcome this, flexible
tells the function to only perform the operation on those parts of the vector that contain the string sep
.
the element the user wishes to extract
Dustin Fife
1 2 3 4 | barcode = c("Case-001-B", "Control-001-A", "Case-002-A", "001")
subsetString(barcode, sep="-", position=2, flexible=TRUE)
subsetString(barcode, sep="-", position=3, flexible=TRUE)
subsetString(barcode, sep="-", position=3, flexible=FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.