% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/format.data.R
\name{format.data}
\alias{format.data}
\title{Format data}
\usage{
\method{format}{data}(
  x,
  id.col = "id",
  date.col = "date",
  size.col = "size",
  units = "years",
  retain = "max",
  seed = 1701
)
}
\arguments{
\item{x}{(data frame) Input data containing one row per capture event and columns for individual ID, date/time (formatted as a Date or POSIX), and body size measurement.}

\item{id.col}{(character) Name of column containing unique individual IDs (default = "id")}

\item{date.col}{(character) Name of column containing dates/times (default = "date")}

\item{size.col}{(character) Name of column containing body size measurements (default = "size")}

\item{units}{(character) Units to be returned for time intervals between measurements. One of "hours", "days", "weeks", "years" (default = "years")}

\item{retain}{(character) Determines how the function should handle more than two measurements per individual. "max" returns the first and last measurement (after removing NAs), "random" = randomly selects two measurements (after removing NAs), "all" = keeps all measurements with growth intervals between measurements 1 and 2, 2 and 3, 3 and 4, etc. Note that "all" results in pseudoreplication. (default = "max")}

\item{seed}{(integer) Seed to use for random selections if \code{retain="random"} (default = 1701).}
}
\value{
Data frame of measurements and capture intervals formatted for MRgrowth functions. Each row is a pair of capture events and associated measurements for an individual.

Column \code{id} = IDs as entered in the input data

Column \code{size1} = size at capture

Column \code{size2} = size at recapture

Column \code{date1} = date at capture

Column \code{date2} = date at recapture

Column \code{td} = time difference between date1 and date2 in the units specified by the units argument.
}
\description{
Format data for other MRgrowth functions
}
\details{
It takes a long-format data frame of capture events and measurements (one row per individual per capture) and converts it into the wide-format (one row per pair of capture events per individual) needed for MRgrowth

If \code{retain} is set to "random", only 1 pair of capture events will be retained per individual. The \code{seed} argument ensures repeatability of the code.

\strong{Note}: Any NA data are removed as part of the function before applying the \code{retain} argument. Thus, if an individual was captured 3 times and only measured the 2nd and 3rd time, the data for the 2nd and 3rd capture events will be returned even if \code{retain="max"}

\strong{Note}: Only individuals with at least 2 capture events (with no NAs) are returned. Any individuals that were never recaptured or did not have all data recorded for at least two recaptures are removed.
}
\examples{

data(MRdata)

#format data with years as the time units and the first and last
#measurement when more than 2 captures are present for an individual.
formatted.data <- format.data(
  x = MRdata,
  id.col = "id",
  date.col = "date",
  size.col = "size",
  units = "years",
  retain = "max"
)
}
