% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/analyseCorrespondanceTable.R
\name{analyseCorrespondenceTable}
\alias{analyseCorrespondenceTable}
\title{Perform analysis on correspondence tables}
\usage{
analyseCorrespondenceTable(
  AB,
  Aname = NULL,
  Bname = NULL,
  A = NULL,
  B = NULL,
  longestAcodeOnly = FALSE,
  longestBcodeOnly = FALSE
)
}
\arguments{
\item{AB}{A mandatory argument containing a data frame provided by the user
with the correspondence table data. The table must contain at least two
columns containing the two classifications \code{A code} and \code{B code}. The name of the two columns is irrelevant.}

\item{Aname}{Optional. A character string specifying the name of the column
in `AB` that should be used as the source classification (`Acode`). If
`NULL`, the function assumes that the first column of `AB` represents the
source classification.}

\item{Bname}{Optional. A character string specifying the name of the column
in `AB` that should be used as the target classification (`Bcode`). If
`NULL`, the function assumes that the second column of `AB` represents the
target classification.}

\item{A}{A data frame containing the source classification data with
an \code{"Acode"} column. Can be \code{NULL} if no source classification
table is provided.}

\item{B}{A data frame containing the target classification data with
a \code{"Bcode"} column. Can be \code{NULL} if no target classification
table is provided.}

\item{longestAcodeOnly}{Logical. If \code{TRUE}, source classification data
are filtered based on \code{"Acode"} retaining only the maximum length,
i.e. the lowest-level Acodes in the correspondence table.}

\item{longestBcodeOnly}{Logical. If \code{TRUE}, target classification data
are filtered based on \code{"Bcode"} retaining only the maximum length,
i.e. the lowest-level Bcodes in the correspondence table.}
}
\value{
A list containing two data frames: \code{Inventory} and \code{Analysis}.
  \code{Inventory} contains statistics related to components, correspondence
  types, and source/target positions. \code{Analysis} contains statistics for
  each class in the correspondence table.
}
\description{
Perform analysis on a correspondence table using its associated
classifications to generate various statistics. It checks the validity of the
input data, identifies components, calculates correspondence types, and
creates summary tables.
}
\examples{
# Use data from the folder extdata/test

AB = read.csv(system.file("extdata/test", "ExempleAnnexe.csv", package = "correspondenceTables"))
head(AB)

result <- analyseCorrespondenceTable(
  AB = AB,
  Aname = NULL,
  Bname = NULL,
  A  = NULL,
  B  = NULL,
  longestAcodeOnly          = FALSE,
  longestBcodeOnly          = FALSE
)

print(result$Inventory)
print(result$Analysis)

# the name of the columns does not matter:
AB_mod = AB
colnames(AB_mod) = c("a", "b")

result_mod <- analyseCorrespondenceTable(
  AB = AB_mod,
  Aname = NULL,
  Bname = NULL,
  A  = NULL,
  B  = NULL,
  longestAcodeOnly          = FALSE,
  longestBcodeOnly          = FALSE
)

print(result_mod$Inventory)
print(result_mod$Analysis)


# examples with using Aname and Bname

# fist we add two more column to the same dataset
set.seed(123)
AB_mod2 = AB_mod

AB_mod2 <- cbind(new_first_col = sample(1:100, nrow(AB_mod2), replace = TRUE), AB_mod2)
AB_mod2 <- cbind(
  AB_mod2[1:2], 
  new_middle_col = sample(1:100, nrow(AB_mod2), replace = TRUE),
  AB_mod2[3:ncol(AB_mod2)]
)
colnames(AB_mod2)

result_mod2 <- analyseCorrespondenceTable(
  AB = AB_mod2,
  Aname = "a",
  Bname = "b",
  A  = NULL,
  B  = NULL,
  longestAcodeOnly          = FALSE,
  longestBcodeOnly          = FALSE
)

print(result_mod2$Inventory)
print(result_mod2$Analysis)

# check if we obtained the same results in all the 3 examples

first = identical(result$Inventory, result_mod$Inventory) 
second = identical(result_mod$Inventory, result_mod2$Inventory)
first && second
# TRUE

# the following won't work as we changed column names in AB_mod, 
# and added new columns in AB_mod2 but the results are the same.
first = identical(result$Analysis, result_mod$Analysis)
second = identical(result_mod$Analysis, result_mod2$Analysis)
first && second
}
