Functions for reshaping respeciate profiles
rsp_dcast
and rsp_melt_wide
reshape supplied
respeciate profile(s). rsp_dcast
converts these from their supplied
long form to a widened form, dcast
ing the data set by either species
or profiles depending on the widen
setting applied.
rsp_dcast_profile
and rsp_dcast_species
are wrappers for these
options. rsp_melt_wide
attempts to return a previously widened data
set to the original long form.
rsp_dcast(rsp, widen = "species")
rsp_dcast_profile(rsp, widen = "profile")
rsp_dcast_species(rsp = rsp, widen = "species")
rsp_melt_wide(rsp, pad = TRUE, drop.nas = TRUE)
A respeciate
object, a data.frame
of respeciate
profiles in standard long form or widened form using
rsp_dcast
and rsp_melt_wide
, respectively.
character, when widening rsp
with
rsp_dcast
, the data type to dcast
,
currently 'species'
(default) or 'profile'
. See Note.
logical or character, when melt
ing a previously widened
data set, should output be re-populated with species and/or profile
meta-data, discarded when widening. This is currently handled by
rsp_pad
. The default TRUE
applies standard settings,
so does not include profile sources reference meta-data. (See
rsp_pad
for other options).
logical, when melt
ing a previously widened
data set, should output be stripped of any rows containing empty
weight/value columns. Because not all profile contains all species, the
dcast
/melt
process can generate empty rows, and this step
attempt account for that when working with standard re(SPECIATE)
profiles. It is, however, sometimes useful to check first, e.g. when
building profiles yourself.
rsp_dcast
returns the wide form of the supplied
respeciate
profile. rsp_melt_wide
returns the (standard) long form of a previously widened profile.
Conventional long-to-wide reshaping of data, or dcast
ing, can
be slow and memory inefficient. So, respeciate
uses the
data.table::dcast
method. The rsp_dcast_species
method,
applied using widen='species'
, is effectively:
dcast(..., profile.id+.profile~.species, value.var=".value")
And, the alternative widen='profile'
:
dcast(..., species.id+.species~.profile, value.var=".value")
Although, respeciate
uses a local version of the SPECIATE
and
SPECIEUROPE
weight measurements .value
, so the EPA and
JCR source information can easily be recovered. See also
rsp_rescale_profile
.
Dowle M, Srinivasan A (2023). _data.table: Extension of `data.frame`_. R package version 1.14.8, <https://CRAN.R-project.org/package=data.table>.