This function allows to transform, factorize, or combine trait measurements into compound measurements or update factor levels into binaries.

mutate.traitdata(.data, ..., values = "traitValue",
  traits = "traitName", units = "traitUnit")

Arguments

.data

the traitdata object to transform

...

named parameters giving definitions of new columns.

values

(NOT TESTED) the column name containing the trait values to be used to fill the matrix (default is traitValue). Duplicate columns (e.g. traitValueStd) will be omitted. See notes.

traits

(NOT TESTED) the column name to be kept for parsing into wide-table (default is traitName). Note that any duplicate column that contains trait names, e.g. traitNameStd will be omitted.

units

(NOT TESTED) the column name containing the units of numerical values (default is traitUnit).

Value

an updated traitdata object with the new trait measures or facts appended to the original table. If the given trait name has been refined, it will be replaced.

Details

The function handles units for numerical traits and returns the new unit of the computed value in column traitUnit, if units of input variables were specified according to the units package. Handling of other columns than traitName and traitValue is not advised at present.

It is advised to mutate traits before applying standardize.traits()! If the mutate function is applied to a standardised dataset, the new trait will not be mapped automatically to the provided thesaurus. (automated re-mapping might be added in later versions of the package.)

Examples

# NOT RUN { pulldata("arthropodtraits") dataset3 <- as.traitdata(arthropodtraits, taxa = "SpeciesID", traits = c("Body_Size", "Dispersal_ability", "Feeding_guild","Feeding_guild_short", "Feeding_mode", "Feeding_specialization", "Feeding_tissue", "Feeding_plant_part", "Endophagous_lifestyle", "Stratum_use", "Stratum_use_short"), units = c(Body_Size = "mm", Dispersal_ability = "unitless"), keep = c(measurementRemark = "Remark"), metadata = list( license = "http://creativecommons.org/publicdomain/zero/1.0/" ) ) head(dataset3) updated <- mutate.traitdata(dataset3, predator = Feeding_guild == "c" ) head(updated[updated$traitName == "predator",]) levels(updated$traitName) # }
## pulldata("heteroptera_raw")
#> The dataset 'heteroptera_raw' is now available for use!
dataset2 <- as.traitdata(heteroptera_raw, traits = c("Body_length", "Body_width", "Body_height", "Thorax_length", "Thorax_width", "Head_width", "Eye_width", "Antenna_Seg1", "Antenna_Seg2", "Antenna_Seg3", "Antenna_Seg4", "Antenna_Seg5", "Front.Tibia_length", "Mid.Tibia_length", "Hind.Tibia_length", "Front.Femur_length", "Hind.Femur_length", "Front.Femur_width", "Hind.Femur_width", "Rostrum_length", "Rostrum_width", "Wing_length", "Wing_width"), taxa = "SpeciesID", occurrences = "ID" )
#> Input is taken to be an occurrence table/an observation -- trait matrix #> (i.e. with individual specimens per row and multiple trait measurements in columns). #> If this is not the case, please provide parameters!
updated <- mutate.traitdata(dataset2, Body_shape = Body_length/Body_width, Body_volume = Body_length*Body_width*Body_height, Wingload = Wing_length*Wing_width/Body_volume) head(updated[updated$traitName %in% c( "Body_volume"),])
#> scientificName traitName traitValue traitUnit measurementID #> 9812 Acalypta nigrina Body_volume 2.080925 mm^3 <NA> #> 9813 Acalypta nigrina Body_volume 1.716540 mm^3 <NA> #> 9814 Acalypta nigrina Body_volume 1.578892 mm^3 <NA> #> 9815 Acalypta nigrina Body_volume 1.498120 mm^3 <NA> #> 9816 Acalypta parvula Body_volume 0.844928 mm^3 <NA> #> 9817 Acalypta parvula Body_volume 0.973056 mm^3 <NA> #> occurrenceID basisOfRecordDescription #> 9812 1 Zoological State Collection Munich #> 9813 2 Zoological State Collection Munich #> 9814 3 Zoological State Collection Munich #> 9815 4 Zoological State Collection Munich #> 9816 5 Zoological State Collection Munich #> 9817 6 Zoological State Collection Munich #> references sex verbatimLocality #> 9812 Treuchtlingen_leg.Seidenstücker_21.5.48 f 48°57’ N 10°55’ E #> 9813 Nürnberg_leg.Seidenstücker_9.7.44 f 49°27’ N 11°05’ E #> 9814 Gunzenshausen_Mfr._leg.Seidenstücker_15.4.58 m 49°07’ N 10°45’ E #> 9815 Nürnberg_leg.Seidenstücker_9.7.44 m 49°27’ N 11°05’ E #> 9816 Nürnberg_Seidenstücker_4.8.45 f 49°27’ N 11°05’ E #> 9817 Erlangen_Seidenstücker_30.9.40 f 49°36’ N 11°00’ E #> #> This trait-dataset contains 26 traits for 179 taxa ( 9386 measurements in total). #> #> heteroptera : Heteroptera morphometry traits by Martin M. Gossner . #> #> When using these data, you must acknowledge the following usage policies: #> #> Cite this trait dataset as: #> Gossner MM, Simons NK, Hoeck L, Weisser WW (2015). “Morphometric #> measures of Heteroptera sampled in grasslands across three regions of #> Germany.” _Ecology_, *96*, 1154. doi: 10.1890/14-2159.1 (URL: #> https://doi.org/10.1890/14-2159.1). #> #> Published under: http://creativecommons.org/publicdomain/zero/1.0/ #>