Skip to contents

Searches rows/columns by name in an array-like object.

Usage

seek_columns(x, ...)

seek_rows(x, ...)

# S4 method for class 'data.frame'
seek_rows(x, select = NULL, names = NULL, ...)

# S4 method for class 'matrix'
seek_rows(x, select = NULL, names = NULL, ...)

# S4 method for class 'data.frame'
seek_columns(x, select = NULL, names = NULL, ...)

# S4 method for class 'matrix'
seek_columns(x, select = NULL, names = NULL, ...)

Arguments

x

An R object (should be a matrix or a data.frame).

...

Further arguments to be passed to select.

select

A function to be applied to the row/column names (e.g. startsWith()) that returns an integer or logical vector.

names

A character vector of row/column names to look for. Only used if select is NULL.

Value

An integer vector or NULL (if x does not have row/column names).

See also

Other data preparation tools: append_column(), append_rownames(), assign(), compact(), count(), detect(), discard(), get(), keep()

Author

N. Frerebeau

Examples

## Seek columns
seek_columns(iris, select = startsWith, prefix = "Petal")
#> [1] 3 4
seek_columns(iris, names = c("Petal.Length", "Petal.Width"))
#> [1] 3 4

## Get columns
x <- get_columns(iris, select = startsWith, prefix = "Petal")
head(x)
#>   Petal.Length Petal.Width
#> 1          1.4         0.2
#> 2          1.4         0.2
#> 3          1.3         0.2
#> 4          1.5         0.2
#> 5          1.4         0.2
#> 6          1.7         0.4

x <- get_columns(iris, names = c("Petal.Length", "Petal.Width"))
head(x)
#>   Petal.Length Petal.Width
#> 1          1.4         0.2
#> 2          1.4         0.2
#> 3          1.3         0.2
#> 4          1.5         0.2
#> 5          1.4         0.2
#> 6          1.7         0.4