Skip to contents

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

Usage

cast.traitdata(
  .data,
  values = "verbatimTraitValue",
  traits = "verbatimTraitName",
  units = "verbatimTraitUnit",
  fun.aggregate = NULL
)

Arguments

.data

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

values

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.

traits

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.

units

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

fun.aggregate

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

Value

a wide-table data.frame object containing all taxa (and other differentiating parameters) in rows and all traits (extracted from column 'verbatimTraitName') 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 '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().

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.

Examples


pulldata("arthropodtraits")
#> Direct call to data source failed. Please check internet connectivity and re-load data!
#> The dataset 'arthropodtraits' has successfully been downloaded! 
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"),
                         keep = c(measurementRemark = "Remark"),
                         metadata = as.metadata(
                            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)
#>   verbatimScientificName verbatimTraitName verbatimTraitValue verbatimTraitUnit
#> 1   Anyphaena accentuata         Body_Size               6.25                mm
#> 2   Aculepeira ceropegia         Body_Size                 11                mm
#> 3       Agalenatea redii         Body_Size               6.93                mm
#> 4     Araneus diadematus         Body_Size              11.88                mm
#> 5      Araneus marmoreus         Body_Size              10.03                mm
#> 6      Araneus quadratus         Body_Size              12.25                mm
#>   measurementID measurementRemark
#> 1             1                  
#> 2             2                  
#> 3             3                  
#> 4             4                  
#> 5             5                  
#> 6             6                  
#> 
#> This trait-dataset contains 11 traits for 1230 taxa ( 10238 measurements in total).
#> 
#> [ ] : 
#>     When using these data, you must acknowledge the following usage policies: 
#> 
#>     Published under: http://creativecommons.org/publicdomain/zero/1.0/ 
#> 
#>     This dataset conforms to: [1] "Ecological Trait-data Standard (ETS) v0.10"
#> 

dd3 <-cast.traitdata(dataset3)
head(dd3)
#>      verbatimScientificName measurementRemark Body_Size Dispersal_ability
#> 1          Acalypta nigrina                    2.6 [mm]              0.25
#> 2          Acalypta parvula                    2.0 [mm]              0.25
#> 3      Acalypta platycheila                    2.6 [mm]              0.25
#> 4         Acalyptus carpini                 *  2.2 [mm]                 1
#> 5 Acanthodelphax denticauda                    3.0 [mm]               0.5
#> 6   Acanthodelphax spinosus                    2.0 [mm]                 0
#>   Endophagous_lifestyle Feeding_guild Feeding_guild_short Feeding_mode
#> 1                  <NA>             h                   h            s
#> 2                  <NA>             h                   h            s
#> 3                  <NA>             h                   h            s
#> 4                  <NA>             h                   h            c
#> 5                  <NA>             h                   h            s
#> 6                  <NA>             h                   h            s
#>   Feeding_plant_part Feeding_specialization Feeding_tissue Stratum_use
#> 1               <NA>                      o              m           g
#> 2               <NA>                      o              m           g
#> 3               <NA>                      o              m           g
#> 4                l-r                      m           <NA>           t
#> 5               <NA>                      m              p           h
#> 6               <NA>                      m              p           h
#>   Stratum_use_short
#> 1                 g
#> 2                 g
#> 3                 g
#> 4                 t
#> 5                 h
#> 6                 h