% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dendro.resample.R
\name{dendro.resample}
\alias{dendro.resample}
\title{Resampling temporal resolution of dendrometer and climate data}
\usage{
dendro.resample(
  df,
  by,
  value = "mean",
  method = c("auto", "aggregate", "interpolate")
)
}
\arguments{
\item{df}{A dataframe with the first column containing date-time values in
the format \code{yyyy-mm-dd HH:MM:SS}.}

\item{by}{A character string defining the target temporal resolution.
Supported values are:
\itemize{
  \item \code{"M"} for minutes
  \item \code{"H"} for hours
  \item \code{"D"} for days
  \item \code{"W"} for weeks
  \item \code{"ME"} for month-end
  \item values such as \code{"10M"}, \code{"30M"}, \code{"5H"},
  \code{"2D"}, or \code{"3W"} for custom multiples
}}

\item{value}{A character string defining the aggregation function.
Supported values are \code{"mean"}, \code{"max"}, \code{"min"},
\code{"sum"}, and \code{"count"}.
The \code{"count"} option returns the number of non-\code{NA} values
within each aggregation interval. It is only valid when
\code{method = "aggregate"}.}

\item{method}{A character string defining how resampling should be performed.
Options are:
\itemize{
  \item \code{"auto"}: automatically aggregates when the requested
  resolution is coarser than the input data, and interpolates when the
  requested resolution is finer
  \item \code{"aggregate"}: always aggregates values within each target
  interval
  \item \code{"interpolate"}: always interpolates to the requested regular
  time grid
}}
}
\value{
A dataframe with resampled data. The first column contains the new
  time stamps and the remaining columns contain the resampled variables.
}
\description{
This function changes the temporal resolution of dendrometer and climate
time series. It supports both aggregation to coarser resolutions and
interpolation to finer resolutions. The target resolution can be defined in
minutes, hours, days, weeks, or month-end frequency. Aggregation can be
performed using \code{mean}, \code{max}, \code{min}, \code{sum}, or
\code{count} (number of non-missing values). When a finer temporal
resolution than the original data is requested, the function can interpolate
the series to the new time step using linear interpolation.
}
\examples{
\donttest{
library(dendRoAnalyst)
data(nepa17)

# Monthly resampling using maximum values
resample_ME <- dendro.resample(df = gf_nepa17, by = "ME", value = "max")
head(resample_ME, 10)

# Daily resampling using mean values
resample_D <- dendro.resample(df = gf_nepa17, by = "D", value = "mean")

# Count non-missing values per day
resample_count <- dendro.resample(df = gf_nepa17, by = "D", value = "count",
                                  method = "aggregate")

# Interpolate to 30-minute resolution
resample_30M <- dendro.resample(df = gf_nepa17, by = "30M", value = "mean",
                                method = "auto")
}

}
