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, dcasting the data set by either species
or profiles depending on the widen setting applied.
rsp_dcast_profile, rsp_dcast_profile_id,
rsp_dcast_species and rsp_dcast_species_id 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_profile_id(rsp, widen = "profile.id")
rsp_dcast_species(rsp = rsp, widen = "species")
rsp_dcast_species_id(rsp = rsp, widen = "species.id")
rsp_melt_wide(rsp, pad = FALSE, drop.nas = FALSE)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), 'species.id', 'profile'
or 'profile.id'. See Note.
logical or character, when melting 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 FALSE does not pad, TRUE
pads, applies standard settings, so does not include profile sources
reference meta-data. (See rsp_pad for other options).
logical, when melting 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 reSPECIATE
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 dcasting, 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")
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>.