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

cast.traitdata(.data, values = "traitValue", traits = "traitName",
  units = "traitUnit", 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 traitValue). Duplicate columns (e.g. traitValueStd) will be omitted. See notes.

traits

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

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

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

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")
#> The dataset 'arthropodtraits' is now available for use!
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)
#> 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 ( 10238 measurements in total). #> #> [ ] : #> When using these data, you must acknowledge the following usage policies: #> #> Published under: http://creativecommons.org/publicdomain/zero/1.0/ #>
dd3 <-cast.traitdata(dataset3) head(dd3)
#> scientificName 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 #> 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