R: Extract several single elements from a string.

str_elems {strex} | R Documentation

## Extract several single elements from a string.

### Description

Efficiently extract several elements from a string. See `str_elem()` for extracting single elements. This function is vectorized over the first argument.

### Usage

    str_elems(string, indices, byrow = TRUE)

### Arguments

`string` | A character vector.
`indices` | A vector of integerish values. Negative indexing is allowed as in `stringr::str_sub()`.
`byrow` | Should the elements be organised in the matrix with one row per string (`byrow = TRUE`, the default) or one column per string (`byrow = FALSE`). See examples if you don't understand.

### Value

A character matrix.

### See Also

Other single element extractors: `str_elem`, `str_paste_elems`

### Examples

    string <- c("abc", "def", "ghi", "vwxyz")
    str_elems(string, 1:2)
    str_elems(string, 1:2, byrow = FALSE)
    str_elems(string, c(1, 2, 3, 4, -1))

[Package strex version 1.2.0 Index]