Description Usage Arguments Details Value Examples
View source: R/compute_column.R
This is a simple helper function which allows you to compute a column based on a row (a single species) from the output of find_species_traits or Databases::search(). For example, you may search multiple databases for body mass information, and have multiple bodymass values for a single species. You can use this helper function to calculate a single value for the species.
1 | compute_column(input, calculator)
|
input |
A dataframe (usually returned from |
calculator |
A function that calculates a value for the species. It takes a single argument,
which is a list where the name of the list is the same as the column names in the
|
Alternatively, you may need to process trait information in some way. This function can also help you do that.
A vector
with a length equivalent to the number of rows in the input
dataframe,
where each value is the result of applying the calculator
function to the row of the
dataframe.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | input <- data.frame(
species_name = c( "Equus quagga", "Ursus maritimus", "Tachyglossus aculeatus" ),
bodymass_from_database1 = c( 25, 120, 80 ),
bodymass_from_database2 = c( 27, 126, 79 )
)
input$mean_bodymass = compute_column( input, function( species ) {
bodymass_values = c( species[["bodymass_from_database1"]], species[["bodymass_from_database2"]] )
return( mean( bodymass_values ) )
})
print(input)
# species_name bodymass_from_database1 bodymass_from_database2 mean_bodymass
# 1 Equus quagga 25 27 26.0
# 2 Ursus maritimus 120 126 123.0
# 3 Tachyglossus aculeatus 80 79 79.5
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.