ir object from wide to longPivot an ir object from wide to long
pivot_wider.ir(
data,
id_cols = NULL,
names_from = "name",
names_prefix = "",
names_sep = "_",
names_glue = NULL,
names_sort = FALSE,
names_repair = "check_unique",
values_from = "value",
values_fill = NULL,
values_fn = NULL,
...
)data in a wide format. If the spectra column is dropped
or invalidated (see ir_new_ir()), the ir class is dropped, else the
object is of class ir.
An object of class ir.
<tidy-select> A set of columns that
uniquely identify each observation. Typically used when you have
redundant variables, i.e. variables whose values are perfectly correlated
with existing variables.
Defaults to all columns in data except for the columns specified through
names_from and values_from. If a tidyselect expression is supplied, it
will be evaluated on data after removing the columns specified through
names_from and values_from.
<tidy-select> A pair of
arguments describing which column (or columns) to get the name of the
output column (names_from), and which column (or columns) to get the
cell values from (values_from).
If values_from contains multiple values, the value will be added to the
front of the output column.
String added to the start of every variable name. This is
particularly useful if names_from is a numeric vector and you want to
create syntactic variable names.
If names_from or values_from contains multiple
variables, this will be used to join their values together into a single
string to use as a column name.
Instead of names_sep and names_prefix, you can supply
a glue specification that uses the names_from columns (and special
.value) to create custom column names.
Should the column names be sorted? If FALSE, the default,
column names are ordered by first appearance.
What happens if the output has invalid column names?
The default, "check_unique" is to error if the columns are duplicated.
Use "minimal" to allow duplicates in the output, or "unique" to
de-duplicated by adding numeric suffixes. See vctrs::vec_as_names()
for more options.
Optionally, a (scalar) value that specifies what each
value should be filled in with when missing.
This can be a named list if you want to apply different fill values to different value columns.
Optionally, a function applied to the value in each cell
in the output. You will typically use this when the combination of
id_cols and names_from columns does not uniquely identify an
observation.
This can be a named list if you want to apply different aggregations
to different values_from columns.
Additional arguments passed on to methods.
Other tidyverse:
arrange.ir(),
distinct.ir(),
extract.ir(),
filter-joins,
filter.ir(),
group_by,
mutate,
mutate-joins,
nest,
pivot_longer.ir(),
rename,
rowwise.ir(),
select.ir(),
separate.ir(),
separate_rows.ir(),
slice,
summarize,
unite.ir()
## pivot_wider
ir_sample_data |>
tidyr::pivot_longer(
cols = dplyr::any_of(c("holocellulose", "klason_lignin"))
) |>
tidyr::pivot_wider(names_from = "name", values_from = "value")
Run the code above in your browser using DataLab