GitLab at IIASA

groupstats.Rd 1.93 KiB
Newer Older
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{groupstats}
\alias{groupstats}
\title{Generate descriptive statistics and save to GDX}
\usage{
groupstats(
  filename,
  BINDir,
  gdxmap,
  mapping,
  cols,
  w,
  writegdx = TRUE,
  filtern = FALSE
)
}
\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{cols}{Which columns to derive descriptive statistics from}

\item{w}{Column with the Weights for the weighted mean}

\item{writegdx}{Logical. If `TRUE`, it writes a GDX with the descriptive statistics.}

\item{filtern}{Logical. If `TRUE`, results will be limited to more than 15 observations per variable for reporting}
}
\value{
A tibble `tbl_df`.
}
\description{
`groupstats()` returns descriptive statistics per group based on the mapping given. For example, if your mapping
is 'regions', this function will give you the weighted mean, median, min, max, number of observations per variable for each
region based on the individual farm data. When `writegdx` is `TRUE`, it writes the GDX in the format 'farmStats_(mapping).gdx'
}
\examples{
BINDir <- "inst/extdata/GAMS"
datafile <- 'FarmDynRexampledata.gdx'
groupstats('FarmDynRexampledata.gdx',
            BINDir="inst/extdata/GAMS/",
            gdxmap = 'map2binid',
            mapping = 'mapping',
            cols = c('a', 'b'),
            w='Weight')
}
\seealso{
\itemize{
\item{\code{\link{summary]}}}{summary statistics}
\item{\code{\link[psych]{describe}}}{Descriptive statistics}
\item{\code{\link[gdxrrw]{wgdx}}}{Write R data to GDX}
\item{\code{\link[gdxrrw]{wgdx.lst}}}{Write multiple symbols to GDX}
\item{\code{\link[tidyr]{pivot_longer}}}{Make dataframes longer}
}
}