From 93d18f3cb8e8c82187b1c91bc0ef774bf5ecbe7c Mon Sep 17 00:00:00 2001 From: "Stratton, Kelly G" Date: Mon, 4 Oct 2021 13:30:25 -0700 Subject: [PATCH] update n_present() function to handle NAs for presence/absence and abundance data_scale options --- R/group_summary_functions.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/group_summary_functions.R b/R/group_summary_functions.R index bbf1ea7..3c94ac1 100644 --- a/R/group_summary_functions.R +++ b/R/group_summary_functions.R @@ -7,15 +7,15 @@ n_present <- function(x, data_scale) { if (data_scale %in% c('pres', 'abundance')) { if (identical(dim(x), NULL)) { # vector - res <- as.integer(x>0) + res <- as.integer(x>0 & !is.na(x)) } else { # 2-dimensional - res <- as.integer(rowSums(x>0)) + res <- as.integer(rowSums(x>0, na.rm = TRUE)) } } else { if (identical(dim(x), NULL)) { # vector res <- as.integer(!is.na(x)) } else { # 2-dimensional - res <- as.integer(rowSums(!is.na(x))) + res <- as.integer(rowSums(!is.na(x), na.rm = TRUE)) } } return(data.frame(n_present=res))