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

mutate.traitdata(.data, ...)

Arguments

.data

the traitdata object to transform

...

named parameters giving definitions of new columns.

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

Note that units for numerical traits will not be maintained or computed (e.g. for ratios). They should be assigned later through the thesaurus() function.

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

data(arthropodtraits)
#> loading dataset 'arthropodtraits' from original data source! #> When using this data, please cite the original publication: #> Gossner MM, Simons NK, Achtziger R, Blick T, Dorow W, Dziock F, Köhler #> F, Rabitsch W and Weisser WW (2015). A summary of eight traits of #> Coleoptera, Hemiptera, Orthoptera and Araneae, occurring in grasslands #> in Germany. _Scientific Data_, *2*, pp. 150013. doi: #> 10.1038/sdata.2015.13 (URL: http://doi.org/10.1038/sdata.2015.13).
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/") )
#> Input is taken to be a species -- trait matrix. If this is not the case, please provide parameters!
head(dataset3)
#> scientificName traitName traitValue traitUnit measurementID #> 1 Anyphaena accentuata Body_Size 6.25 mm 1 #> 2 Aculepeira ceropegia Body_Size 11 mm 2 #> 3 Agalenatea redii Body_Size 6.93 mm 3 #> 4 Araneus diadematus Body_Size 11.88 mm 4 #> 5 Araneus marmoreus Body_Size 10.03 mm 5 #> 6 Araneus quadratus Body_Size 12.25 mm 6 #> measurementRemark #> 1 #> 2 #> 3 #> 4 #> 5 #> 6 #> #> This trait-dataset contains 11 traits for 1230 taxa ( 6 measurements in total). #> #> [1]: #> When using these data must acknowledge the following usage policies: #> #> Published under: http://creativecommons.org/publicdomain/zero/1.0/ #>
updated <- mutate.traitdata(dataset3, predator = Feeding_guild == "c" ) head(updated[updated$traitName == "predator",])
#> scientificName traitName traitValue traitUnit measurementID #> 10239 Acalypta nigrina predator FALSE <NA> <NA> #> 10240 Acalypta parvula predator FALSE <NA> <NA> #> 10241 Acalypta platycheila predator FALSE <NA> <NA> #> 10242 Acalyptus carpini predator FALSE <NA> <NA> #> 10243 Acanthodelphax denticauda predator FALSE <NA> <NA> #> 10244 Acanthodelphax spinosus predator FALSE <NA> <NA> #> measurementRemark #> 10239 #> 10240 #> 10241 #> 10242 * #> 10243 #> 10244 #> #> This trait-dataset contains 12 traits for 1230 taxa ( 6 measurements in total). #> #> [1]: #> When using these data must acknowledge the following usage policies: #> #> Published under: http://creativecommons.org/publicdomain/zero/1.0/ #>
levels(updated$traitName)
#> [1] "Body_Size" "Dispersal_ability" "Feeding_guild" #> [4] "Feeding_guild_short" "Feeding_mode" "Feeding_specialization" #> [7] "Feeding_tissue" "Feeding_plant_part" "Endophagous_lifestyle" #> [10] "Stratum_use" "Stratum_use_short" "predator"
## 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)
#> Error in is.data.frame(.data): object 'dataset2' not found
head(updated[updated$traitName %in% c("Body_shape", "Body_volume", "Wingload"),])
#> [1] scientificName traitName traitValue traitUnit #> [5] measurementID measurementRemark #> <0 rows> (or 0-length row.names) #> #> This trait-dataset contains 12 traits for 1230 taxa ( 0 measurements in total). #> #> [1]: #> When using these data must acknowledge the following usage policies: #> #> Published under: http://creativecommons.org/publicdomain/zero/1.0/ #>