Turns wide-table formats (species-traits matrix and occurrence table) into long-table format. As input, the function requires information about which columns contain traits, given as a list of trait-names, and which column contains the taxon name. For tables containing repeated measurements of traits within the same taxon, an occurrenceID should be given or will be created.

as.traitdata(x, traits = NULL, taxa, individuals = NULL,
  occurrences = individuals, datasetID = NULL, measurements = NULL,
  units = NULL, keep = NULL, drop = NULL, na.rm = TRUE,
  id.vars = names(x)[names(x) %in% keep & !names(x) %in% drop],
  mutate = NULL, thesaurus = NULL, metadata = list(rightsHolder = NULL,
  bibliographicCitation = NULL, license = NULL, author = NULL, datasetID =
  datasetID, datasetName = NULL, version = NULL), ...)



data.frame object, containing at least a column of taxa, and one or more columns of trait measurements.


a vector of column names containing traits.


the name of the column containing taxon names.


identical to occurrence. (old term kept for clarification)


either a column name containing identifiers for each individual specimen on which several traits were measured, i.e. an occurrence of this taxon, or a vector of occurrence identifiers which must be of the same length as the number of rows of the table. See 'Details'.


a unique name for this dataset (optional). Will be prepended to the occurrence ID and measurement ID.


either a column name containing identifiers for each individual measurement, or a vector of measurement identifiers. This applies, if single trait measurements span across multiple columns of data, e.g. multivariate traits like quantitative measures of chemical compounds, wavelengths or x-y-z coordinates. In most cases, a measurementID will link the data across rows in the longtable format. Make sure that the traitnames given reflect the different dimensions of the trait measurement. If measurement remains blank, sequential identifiers will be auto-generated for each measured value.


a single character string or named vector giving the units that apply to the traits. If only one unit type is given, it will be applied to all traits.


a vector or named vector containing the names of the input columns to be kept in the output. Vector names will be used to rename the columns. It is recommended to use accepted column names of the traitdata standard for renaming!


a vector acting as the inverse of keep. All columns listed will be removed from the output dataset.


logical defaults to TRUE. If FALSE, all measured Values containing NA will be kept in the output table. This is not reccomended for most data.


a list of named entries, according to the terms for metadata of the traitdata standard. Metadata will be added as attributes to the data table. Possible entries are: rightsHolder, bibliographicCitation, license, author, datasetID, datasetName, version. (see 'Details')



If occurrence is left blank, the script will check for the structure of the input table. If several entries are given for the same taxon, it assumes that input is an occurrence table and assigns identifiers.

Metadata will be stored as attributes to the data frame and can be accessed via attributes(). It is not necessary but highly recommended to provide metadata when working with multiple trait data files. When appending datasets using rbind(), the metadata will be stored in additional columns.


# species-trait matrix: data(carabids)
#> loading dataset 'carabids' from original data source! #> When using this data, please cite the original publication: #> van der Plas F, van Klink R, Manning P, Olff H and Fischer M (2017). #> Sensitivity of functional diversity metrics to sampling intensity. #> _Methods in Ecology and Evolution_. doi: 10.1111/2041-210x.12728 (URL: #> http://doi.org/10.1111/2041-210x.12728).
dataset1 <- as.traitdata(carabids, taxa = "name_correct", traits = c("body_length", "antenna_length", "metafemur_length"), units = "mm", keep = c(datasetID = "source_measurement", measurementRemark = "note"), metadata = list( bibliographicCitation = attributes(carabids)$citeAs, author = "Fons van der Plas", 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!
# occurrence table: data(heteroptera_raw)
#> loading dataset 'heteropteraRaw' from original data source! #> When using this data, please cite the original publication: #> Gossner MM, Simons NK, Höck L and Weisser WW (2015). Morphometric #> measures of Heteroptera sampled in grasslands across three regions of #> Germany. _Ecology_, *96*, pp. 1154. doi: 10.1890/14-2159.1 (URL: #> http://doi.org/10.1890/14-2159.1).
dataset2 <- as.traitdata(heteroptera_raw, taxa = "SpeciesID", traits = c("Body_length", "Body_width", "Body_height", "Thorax_length", "Thorax_width", "Head_width", "Eye_width", "Antenna_Seg1", "Antenna_Seg2", "Antenna_Seg3", "Antenna_Seg4", "Antenna_Seg5", "Front.Tibia_length", "Mid.Tibia_length", "Hind.Tibia_length", "Front.Femur_length", "Hind.Femur_length", "Front.Femur_width", "Hind.Femur_width", "Rostrum_length", "Rostrum_width", "Wing_length", "Wing_widt"), units = "mm", keep = c(sex = "Sex", references = "Source", lifestage = "Wing_development"), metadata = list( author = "Gossner MM, Simons NK, Höck L and Weisser WW", datasetName = "Morphometric traits Heteroptera", bibliographicCitation = attributes(heteroptera_raw)$citeAs, license = "http://creativecommons.org/publicdomain/zero/1.0/" ) )
#> it seems you are providing repeated measures of traits on multiple specimens of the same species (i.e. an occurrence table)! Sequential identifiers for the occuences will be added. If your dataset contains user-defined occurrenceIDs you may specify the column name in parameter 'occurrences'.