Extract a character column in an ir
object into multiple columns using regular expression groups
Source: R/tidyverse.R
extract.ir.Rd
Extract a character column in an ir
object into multiple columns using regular expression groups
Arguments
- data
An object of class
ir
.- col
Column name or position. This is passed to
tidyselect::vars_pull()
.This argument is passed by expression and supports quasiquotation (you can unquote column names or column positions).
- into
Names of new variables to create as character vector. Use
NA
to omit the variable in the output.- regex
A string representing a regular expression used to extract the desired values. There should be one group (defined by
()
) for each element ofinto
.- remove
If
TRUE
, remove input column from output data frame.- convert
If
TRUE
, will runtype.convert()
withas.is = TRUE
on new columns. This is useful if the component columns are integer, numeric or logical.NB: this will cause string
"NA"
s to be converted toNA
s.- ...
Additional arguments passed on to methods.
Value
data
with an extracted character column. See
tidyr::extract()
.
See also
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
Examples
## extract
ir_sample_data %>%
tidyr::extract(
id_sample, "a"
)
#> # A tibble: 58 × 7
#> id_measurement a sample_type sample_comment klason_lignin holocellulose
#> <int> <chr> <chr> <chr> <units> <units>
#> 1 1 GN needles Abies Firma Mom… 0.359944 0.3084
#> 2 2 GN needles Cupressocyparis… 0.339405 0.2497
#> 3 3 GN needles Juniperus chine… 0.267552 0.3362
#> 4 4 GN needles Metasequoia gly… 0.350016 0.1844
#> 5 5 GN needles Pinus strobus T… 0.331100 0.3092
#> 6 6 GN needles Pseudolarix ama… 0.279360 0.3355
#> 7 7 GN needles Sequoia semperv… 0.329672 0.2408
#> 8 8 GN needles Taxodium distic… 0.356950 0.1253
#> 9 9 GN needles Thuja occidenta… 0.369360 0.2517
#> 10 10 GN needles Tsuga carolinia… 0.289050 0.3487
#> # … with 48 more rows, and 1 more variable: spectra <named list>