% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/main.r
\name{replace_zeros}
\alias{replace_zeros}
\title{Replace zero values in count or frequency data}
\usage{
replace_zeros(
  df,
  rep_method = c("counts", "frac_min"),
  pseudo_count = 0.5,
  pseudo_frac_min = 2/3,
  add_to = NULL
)
}
\arguments{
\item{df}{A data frame or matrix where zeros need to be replaced.}

\item{rep_method}{Character string specifying the replacement strategy. One
of \code{"counts"}, or \code{"frac_min"}.}

\item{pseudo_count}{Numeric (default: 0.5). Used if \code{rep_method =
"counts"}.}

\item{pseudo_frac_min}{Numeric (default: 2/3). The multiplier for the minimum
non-zero value when \code{rep_method = "frac_min"}.}

\item{add_to}{Character string. Should the value be added to \code{"all"}
cells or just the \code{"zeros"}?}
}
\value{
A data frame or matrix of the same dimensions as \code{df} with all
zero values replaced by the calculated replacement value.
}
\description{
This function replaces zero values in a data frame or matrix to facilitate
downstream transformations that require strictly positive values, such as the
Centered Log-Ratio (CLR) transformation.
}
\details{
The function provides two methods for handling zeros:
\itemize{
\item \strong{counts:} Adds a fixed value (\code{pseudo_count}).
\item \strong{frac_min:} Replaces zeros with a fraction
(\code{pseudo_frac_min}) of the smallest observed non-zero value in
the dataset.
}
}
\examples{
# Replace zeros in a count matrix
counts_df <- data.frame(A = c(10, 0, 5), B = c(20, 10, 0))
replace_zeros(counts_df, rep_method = "counts", add_to = "all")

# Replace zeros in a frequency matrix
freq_df <- data.frame(A = c(0.5, 0.5), B = c(0.2, 0.8), C = c(0.0, 1.0))
replace_zeros(freq_df, rep_method = "frac_min", add_to = "zeros")
}
