Learn R Programming

fifer (version 1.0)

subsetString: Extract only part of a string

Description

Extract only part of a string, given a separator

Usage

subsetString(string, sep = " ", position = 3)

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

Value

the element the user wishes to extract

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).

Examples

Run this code
barcode = c("Case-001-B", "Control-001-A", "Case-002-A")
subsetString(barcode, sep="-", position=2)
subsetString(barcode, sep="-", position=3)

Run the code above in your browser using DataLab