Skip to contents

This function outputs a data.frame that summarises the species by trait table to have many information in a glance. This can then return a data.frame or a nicely formatted knitr::kable() for inclusion in an Rmarkdown document.

Usage

fb_table_trait_summary(species_traits, kable = FALSE)

Arguments

species_traits

a data.frame with species in rows and traits as columns. NOTE: The first column should be named "species" and contain species names. The other columns should be named according to trait names.

kable

TRUE or FALSE Should function returns a knitr::kable()? defaults FALSE

Value

a data.frame with the following columns:

  • trait_name: a character column with the trait name as indicated in species_traits

  • trait_type: the nature of the trait (numeric, categorical, or ordered)

  • number_non_missing: the total number of non-NA trait values

  • proportion_non_missing: the proportion of non-NA trait values

  • trait_range: for numerical traits, the range of values

  • trait_mean_sd: for numerical traits, the mean plus-minus the standard deviation

  • number_distinct: for non-numerical traits, the number of categories

  • list_distinct: for non-numerical traits, the list of categories

Examples

# Get a data.frame back
fb_table_trait_summary(species_traits)
#>            trait_name trait_type number_non_missing proportion_non_missing
#> 1     adult_body_mass    numeric                123                   83 %
#> 2    gestation_length    numeric                 88                   59 %
#> 3         litter_size    numeric                114                   77 %
#> 4       max_longevity    numeric                 81                   54 %
#> 5 sexual_maturity_age    numeric                 84                   56 %
#> 6        diet_breadth    numeric                 83                   56 %
#>     trait_range    trait_mean_sd number_distinct list_distinct
#> 1 2.26-675876.7 18809.7ற79086.68              NA          <NA>
#> 2   19.5-265.99      69.93ற63.58              NA          <NA>
#> 3     0.98-8.99        3.37ற2.03              NA          <NA>
#> 4        12-600    171.28ற117.18              NA          <NA>
#> 5 25.37-1542.25    392.01ற314.88              NA          <NA>
#> 6           1-8        2.46ற1.98              NA          <NA>

# Get a kable (to use in Rmd documents)
fb_table_trait_summary(species_traits, TRUE)
#> 
#> 
#> |Trait Name          |Nature of Trait | Number of Non-Missing Values|Proportion of Non-Missing Values |Range of Trait |Trait Mean ற SD  | Number of Distinct Values|List of Distinct Values |
#> |:-------------------|:---------------|----------------------------:|:--------------------------------|:--------------|:----------------|-------------------------:|:-----------------------|
#> |adult_body_mass     |numeric         |                          123|83 %                             |2.26-675876.7  |18809.7ற79086.68 |                        NA|NA                      |
#> |gestation_length    |numeric         |                           88|59 %                             |19.5-265.99    |69.93ற63.58      |                        NA|NA                      |
#> |litter_size         |numeric         |                          114|77 %                             |0.98-8.99      |3.37ற2.03        |                        NA|NA                      |
#> |max_longevity       |numeric         |                           81|54 %                             |12-600         |171.28ற117.18    |                        NA|NA                      |
#> |sexual_maturity_age |numeric         |                           84|56 %                             |25.37-1542.25  |392.01ற314.88    |                        NA|NA                      |
#> |diet_breadth        |numeric         |                           83|56 %                             |1-8            |2.46ற1.98        |                        NA|NA                      |