cast.traitdata: Cast long-table trait data into wide-table format

View source: R/cast.traitdata.R

cast.traitdataR Documentation

Cast long-table trait data into wide-table format


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


  values = "verbatimTraitValue",
  traits = "verbatimTraitName",
  units = "verbatimTraitUnit",
  fun.aggregate = NULL



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


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


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


the column name containing the units of numerical values (default is verbatimTraitUnit).


option for reshape2::cast() to define method of aggregation.


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 'verbatimTraitValue'.

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().


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

Duplicate columns

The function is currently not able to handle multiple columns of trait data (incl. names and units). Those are currently omitted from the output and may be added manually. You can alter the columns to be used to construct the matrix by specifying those in parameters traits, values, and units. Automatic handling of the Std columns might be added at a later stage.


dataset3 <- as.traitdata(arthropodtraits,
                         taxa = "SpeciesID",
                         traits = c("Body_Size", "Dispersal_ability",
                               "Feeding_mode", "Feeding_specialization",
                               "Feeding_tissue", "Feeding_plant_part",
                               "Endophagous_lifestyle", "Stratum_use",
                         units = c(Body_Size = "mm"),
                         keep = c(measurementRemark = "Remark"),
                         metadata = as.metadata(
                            license = ""


dd3 <-cast.traitdata(dataset3)

traitdataform documentation built on May 25, 2022, 5:07 p.m.