Separate a character column in an ir
object into multiple columns with a regular expression or numeric locations
Source: R/tidyverse.R
separate.ir.Rd
Separate a character column in an ir
object into multiple columns with a regular expression or numeric locations
Usage
separate.ir(
data,
col,
into,
sep = "[^[:alnum:]]+",
remove = TRUE,
convert = FALSE,
extra = "warn",
fill = "warn",
...
)
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.- sep
Separator between columns.
If character,
sep
is interpreted as a regular expression. The default value is a regular expression that matches any sequence of non-alphanumeric values.If numeric,
sep
is interpreted as character positions to split at. Positive values start at 1 at the far-left of the string; negative value start at -1 at the far-right of the string. The length ofsep
should be one less thaninto
.- 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.- extra
If
sep
is a character vector, this controls what happens when there are too many pieces. There are three valid options:"warn" (the default): emit a warning and drop extra values.
"drop": drop any extra values without a warning.
"merge": only splits at most
length(into)
times
- fill
If
sep
is a character vector, this controls what happens when there are not enough pieces. There are three valid options:"warn" (the default): emit a warning and fill from the right
"right": fill with missing values on the right
"left": fill with missing values on the left
- ...
Additional arguments passed on to methods.
Value
.data
with separated columns. If the spectra
column is
dropped or invalidated (see ir_new_ir()
), the ir
class is dropped, else
the object is of class ir
.
See also
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
Examples
## separate
ir_sample_data %>%
tidyr::separate(
col = "id_sample", c("a", "b", "c")
)
#> # A tibble: 58 × 9
#> id_measurement a b c sample_type sample_comment klason_lignin
#> * <int> <chr> <chr> <chr> <chr> <chr> [1]
#> 1 1 GN 11 389 needles Abies Firma Momi … 0.360
#> 2 2 GN 11 400 needles Cupressocyparis l… 0.339
#> 3 3 GN 11 407 needles Juniperus chinens… 0.268
#> 4 4 GN 11 411 needles Metasequoia glypt… 0.350
#> 5 5 GN 11 416 needles Pinus strobus Tor… 0.331
#> 6 6 GN 11 419 needles Pseudolarix amabi… 0.279
#> 7 7 GN 11 422 needles Sequoia sempervir… 0.330
#> 8 8 GN 11 423 needles Taxodium distichu… 0.357
#> 9 9 GN 11 428 needles Thuja occidentali… 0.369
#> 10 10 GN 11 434 needles Tsuga caroliniana… 0.289
#> # … with 48 more rows, and 2 more variables: holocellulose [1],
#> # spectra <named list>