Function to reformat trait data from the long-table into a matrix/wide-table or occurrence table format.

cast.traitdata(.data, summarize_num = mean, summarize_cat)

Arguments

.data

dataset of class 'traitdata' to be cast into wide-table format.

summarize_num

Not functional.

summarize_cat

Not functional.

Value

a wide-table data.frame object containing all taxa (and other differentiating parameters) in rows and all traits (extracted from column 'traitName') in columns.

Details

The wide-table will be composed while preserving the detail given in the dataset (occurrence level or taxa level). The cells will be filled with the values from 'traitValue'.

If taxa should be summarized, provide function for summarizing in parameter 'summarize'. This can be any function that takes a vector and returns a single value for both numerical and factorial/character input vectors!. The default for numerical values is to return an arithmetric mean while including any outliers. For factorial values, the value is accepted if it is equal in all of the input entries. Otherwise NA is returned. For heterogeneous factorial or character input, user action is required for homogenizing the data before calling cast.traitdata().

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).
head(arthropodtraits)
#> Order Suborder Family SpeciesID Author #> 1 Araneae Labidognatha Anyphaenidae Anyphaena accentuata (Walckenaer, 1802) #> 2 Araneae Labidognatha Araneidae Aculepeira ceropegia Walckenaer, 1802 #> 3 Araneae Labidognatha Araneidae Agalenatea redii (Scopoli, 1763) #> 4 Araneae Labidognatha Araneidae Araneus diadematus Clerck, 1757 #> 5 Araneae Labidognatha Araneidae Araneus marmoreus Clerck, 1757 #> 6 Araneae Labidognatha Araneidae Araneus quadratus Clerck, 1757 #> Body_Size Dispersal_ability Feeding_guild Feeding_guild_short Feeding_mode #> 1 6.25 1.00 c c e #> 2 11.00 1.00 c c e #> 3 6.93 0.50 c c e #> 4 11.88 1.00 c c e #> 5 10.03 0.75 c c e #> 6 12.25 1.00 c c e #> Feeding_specialization Feeding_tissue Feeding_plant_part #> 1 <NA> <NA> <NA> #> 2 <NA> <NA> <NA> #> 3 <NA> <NA> <NA> #> 4 <NA> <NA> <NA> #> 5 <NA> <NA> <NA> #> 6 <NA> <NA> <NA> #> Endophagous_lifestyle Stratum_use Stratum_use_short Remark #> 1 <NA> t t #> 2 <NA> h h #> 3 <NA> h h #> 4 <NA> (h)-t u #> 5 <NA> (h)-t u #> 6 <NA> (h)-t u
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/ #>
head(cast.traitdata(dataset3))
#> scientificName measurementRemark Body_Size Dispersal_ability #> 1 Acalypta nigrina 2.6 0.25 #> 2 Acalypta parvula 2 0.25 #> 3 Acalypta platycheila 2.6 0.25 #> 4 Acalyptus carpini * 2.2 1 #> 5 Acanthodelphax denticauda 3 0.5 #> 6 Acanthodelphax spinosus 2 0 #> Feeding_guild Feeding_guild_short Feeding_mode Feeding_specialization #> 1 h h s o #> 2 h h s o #> 3 h h s o #> 4 h h c m #> 5 h h s m #> 6 h h s m #> Feeding_tissue Feeding_plant_part Endophagous_lifestyle Stratum_use #> 1 m <NA> <NA> g #> 2 m <NA> <NA> g #> 3 m <NA> <NA> g #> 4 <NA> l-r <NA> t #> 5 p <NA> <NA> h #> 6 p <NA> <NA> h #> Stratum_use_short #> 1 g #> 2 g #> 3 g #> 4 t #> 5 h #> 6 h