subsetString: Extract only part of a string

Description Usage Arguments Details Value Author(s) Examples

View source: R/subsetString.R

Description

Extract only part of a string, given a separator

Usage

1
subsetString(string, sep = " ", position = 3, flexible = FALSE)

Arguments

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

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.

Value

the element the user wishes to extract

Author(s)

Dustin Fife

Examples

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)

fifer documentation built on May 30, 2017, 7:40 a.m.

Related to subsetString in fifer...