% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mixing_ability.R
\name{pivotMixData2Wide}
\alias{pivotMixData2Wide}
\title{Pivot mixture data into the wide format}
\usage{
pivotMixData2Wide(
  df,
  colIDstand = "ID",
  colIDfocal = "focal",
  colIDneighbors = "neighbor",
  colPlot = c("x", "y"),
  colY = "yield",
  sepY = "_",
  sepFocalNeighbors = NULL
)
}
\arguments{
\item{df}{data frame}

\item{colIDstand}{name of the column containing the identifier of each stand}

\item{colIDfocal}{name of the column containing the identifiers of the focal genotypes}

\item{colIDneighbors}{optional name of the column containing the identifiers of the neighbor genotypes}

\item{colPlot}{name of the column(s) allowing to uniquely identify a plot}

\item{colY}{name of the column containing the yield data}

\item{sepY}{separator used in the name of the new "yield" columns made by concatenating \code{colY} and \code{colIDfocal} or \code{colIDneighbors}}

\item{sepFocalNeighbors}{in case \code{colIDneighbors} is unspecified or does not exist in \code{df}, the distinction between focal and neighbor(s) will be retrieved by splitting \code{colIDstand} using \code{sepFocalNeighbors}}
}
\value{
data.frame
}
\description{
Pivots mixture data into the wide format, from one row per component of each stand (i.e., several rows if the stand is a mixture) into one row per stand.
}
\examples{
## only binary mixtures:
dat0 <- data.frame(
  focal = c("wheat01", "pea02", "wheat01", "pea01"),
  neighbor = c("pea02", "wheat01", "pea01", "wheat01"),
  name = c(
    rep("wheat01-pea02", 2),
    rep("wheat01-pea01", 2)
  ),
  stand = rep("inter", 4),
  x = 1,
  y = c(1, 1, 2, 2),
  yield = c(10, 11, 12, 13),
  stringsAsFactors = TRUE
)
dat0
(dat1 <- pivotMixData2Wide(dat0, colIDstand="name"))

## binary mixtures and a monovarietal:
dat0 <- data.frame(
  focal = c("wheat01", "pea02", "wheat01", "pea01", "wheat01"),
  neighbor = c("pea02", "wheat01", "pea01", "wheat01", "wheat01"),
  name = c(
    rep("wheat01-pea02", 2),
    rep("wheat01-pea01", 2),
    "wheat01"
  ),
  stand = c(rep("inter", 4), "sole"),
  x = 1,
  y = c(1, 1, 2, 2, 3),
  yield = c(10, 11, 12, 13, 20.5),
  stringsAsFactors = TRUE
)
dat0
(dat1 <- pivotMixData2Wide(dat0, colIDstand="name"))

## reverse conversion
dat1v2 <- dat1
colnames(dat1v2)[colnames(dat1v2) == "yield_focal"] <- "yield-cereal"
colnames(dat1v2)[colnames(dat1v2) == "yield_neighbor"] <- "yield-legume"
dat1v2$yield <- apply(dat1v2[,c(7,8)], 1, sum, na.rm=TRUE)
(dat1v2 <- dat1v2[,-c(1,2)])
(dat2 <- pivotMixData2Long(dat1v2, colC="name", sepY="-",
                           genos=list("cereal"=c("wheat01","wheat02"),
                                      "legume"=c("pea01","pea02"))))
all.equal(dat2, dat0)
}
\seealso{
\code{\link{pivotMixData2Long}}
}
\author{
Timothee Flutre
}
