austraits icon indicating copy to clipboard operation
austraits copied to clipboard

summarise_trait_means fails for categorical traits

Open alexskeels opened this issue 11 months ago • 1 comments

Hi there,

Love the package, really great job team!

This is part bug report and part feature reuest... So when transforming the austraits data into wide format, we first have to summarise the cases where we have multiple observations of the same trait for a species, using summarise_trait_means(). The first line of this function is:

suppressWarnings(trait_data <- trait_data %>% dplyr::mutate(value = as.numeric(value), replicates = as.numeric(replicates)))

This line turns all categorical traits into NA. This makes sense for the downstream stuff as you can't get a mean for character vectors anyway. however, I guess the expected outcome of this function is that it would return the modal value of these categorical traits.

So the bug (if it is really a bug and not a feature) is that summarise_trait_means retruns NAs for non numeric traits.

The feature request is whether its possible to have this function or another function return a modal value for these traits? Or, is there another way to summarise the data to get it into a wide format while maintaining these traits? In other words, is there any way to get a wide table with a single value for each species for both numeric and categorical traits?

Thanks very much in advance for this, and again the R package and dataset are fantastic!

To reproduce:

austraits <- load_austraits(version = "3.0.2", path = "data/austraits")

proteaceae <- extract_taxa(austraits, family = "Proteaceae") # subset

data_wide_bound <- proteaceae$traits %>% summarise_trait_means() %>% trait_pivot_wider()

all(is.na(data_wide_bound $value$fire_response)) # TRUE

Desktop (please complete the following information):

  • OS: Windows 10
  • austraits Version 2.1.2
  • R Version 4.3.0

alexskeels avatar Aug 11 '23 03:08 alexskeels