R/length2.R

Defines functions length2

Documented in length2

#' @title Length of a list with or without NA values
#'
#' @description
#' Replacement for length(). Finds count of items like length(), but if set na.rm=TRUE then it doesn't count the items that are NA
#'
#' @param x A vector, required.
#' @param na.rm Logical value, optional, FALSE by default. Should NA values be left out of the count?
#' @return Returns a single number.
#' @examples
#' length2(c(1,2,3,NA))
#' length2(c(1,2,3,NA), na.rm=TRUE)
#' @export
length2 <- function(x, na.rm=FALSE) {
	if(na.rm) 	{sum(!is.na(x))}
	else		{length(x)}
}
ejanalysis/analyze.stuff documentation built on April 2, 2024, 10:10 a.m.