\item{x}{vector from which to retrieve the mode from.}
}
\value{
same class as 'x'.
}
\description{
This function returns the mode of a vector. If the vector contains a character or factor, the most common character/factor is returned. Numbers written as characters will be compatible with non-character numbers (i.e. doubles/numeric), but the function returns a character.
`gdxreshape()` formats the data to be saved in GDX into long format. It is imported from the gdxrrw package with a few improvements for performance and usability, since there is a risk of it being removed from the gdxrrw package in the future.
We would like to thank the R GAMS team for this useful function.
\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.}
}
\value{
A tibble `tbl_df`.
}
\description{
`samplr()` 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'
samplr('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}