Returns rows/columns selected by name in an array-like object.
Usage
get_columns(x, ...)
get_rows(x, ...)
# S4 method for class 'ANY'
get_columns(x, select = NULL, names = NULL, ...)
# S4 method for class 'ANY'
get_rows(x, select = NULL, names = NULL, ...)
Arguments
- x
An R object (should be a
matrix
or adata.frame
).- ...
Further arguments to be passed to
select
.- select
A
function
to be applied to the row/column names (e.g.startsWith()
) that returns aninteger
orlogical
vector.- names
A
character
vector of row/column names to look for. Only used ifselect
isNULL
.
See also
Other data preparation tools:
append_column()
,
append_rownames()
,
assign()
,
compact()
,
count()
,
detect()
,
discard()
,
keep()
,
seek()
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