% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{updateFarmData}
\alias{updateFarmData}
\title{Reshape from wide to long and save to GDX}
\usage{
updateFarmData(
filename,
BINDir,
gdxmap,
mapping,
writegdx = TRUE,
cptcoeffs = FALSE,
farmchars = NULL,
cptcoeffsxl = NULL
)
}
\arguments{
\item{filename}{Name of the GDX file with BIN data and mappings.}
\item{BINDir}{Directory where the FADN data is located.}
\item{gdxmap}{Name of the set in the GDX file that contains the mapping (e.g. Regs2BINID)}
\item{mapping}{Column name of the characteristic/variable to be grouped by (e.g. "Regions" or "Regs")}
\item{writegdx}{Logical. If `TRUE`, it writes a GDX with the descriptive statistics.}
\item{cptcoeffs}{Logical. When this is set to `TRUE` it calculates farm-specific parameters based on CPT coefficients}
\item{farmchars}{GDX file containing farm characteristics}
\item{cptcoeffsxl}{Location of the CPT coefficients excel file}
}
\value{
A tibble `tbl_df`.
}
\description{
`updateFarmData()` creates sample farms by aggregating data based on the weighted mean and the selected mapping for use in FarmDyn.
For non-numerical globals, it summarises based on the mode using the `Modes()` function. When `writegdx` is `TRUE`, it writes the GDX in the format 'farmData_(mapping).gdx'.
}
\examples{
BINDir <- "inst/extdata/GAMS"
datafile <- 'FarmDynRexampledata.gdx'
updateFarmData('FarmDynRexampledata.gdx',
&BINDir="inst/extdata/GAMS/",
&gdxmap = 'map2binid',
&mapping = 'mapping',
&w='Weight')
}
\seealso{
\itemize{
\item{\code{\link[FarmDynR]{gdxbinwider}}}{Widens BIN data directly from GDX}
\item{\code{\link[FarmDynR]{gdxreshape}}}{Lengthens data and saves to GDX}
\item{\code{\link[gdxrrw]{wgdx}}}{Write R data to GDX}
\item{\code{\link[gdxrrw]{wgdx.lst}}}{Write multiple symbols to GDX}
\item{\code{\link[dplyr]{summarise}}}{Make dataframes longer}
\item{\code{\link{weighted.mean]}}}{Calculates weighted mean}
}
}