mysplit: Splits and extracts single value from each entry in a vector...

Description Usage Arguments Value Examples

Description

To be used internally, this function splits a string vector using a given separator, extracts one of the results and combines all extracted results in a vector. The split is done by using strsplit. This function was written to be used sequentially on a vector via sapply.

Usage

1
mysplit(xi, char.vector, split.by, result.sel, fixed = FALSE)

Arguments

xi

the element to be selected, typically is a number varying from 1 to the length of the character vector.

char.vector

the character vector containing the strings to be split.

split.by

the string to be used to split each entry in char.vector - see strsplit for details.

result.sel

integer indicating the index of the element after splitting to be selected.

fixed

logical, to be passed on to strsplit. strsplit returns a list of results, of which the one with index result.sel is selected.

Value

A single string.

Examples

1
2
3
4
5
xs <- paste(LETTERS[1:5], 5:1, sep="_")
xs
sapply(1:length(xs), mysplit, char.vector = xs, split.by = "_", result.sel = 1)
# Compare it with the result from directly applying strsplit:
strsplit(xs, "_")

rxmenezes/rscreenorm documentation built on May 15, 2019, 1:19 p.m.