df2genind: Convert a data.frame of genotypes to a genind object, and conversely.
Description
The function df2genind converts a data.frame (or a matrix) into
a genind object. The data.frame must meet the following
requirements:
- genotypes are in row (on row per genotype)
- markers are in columns
- each element is a string of (2, 4 or 6) characters coding both alleles without
separation. Missing values are coded by NA or zeros. Uncomplete
strings are filled with "0" at the begining. For instance, "912" in a
4-characters coding scheme is interpreted as "0912", thus as an
heterozygote with alleles "09" and "12". Note that this format is the
one of GENETIX for a 6-characters coding scheme
The function genind2df converts a genind back to
such a data.frame.
an optional integer the number of characters used for coding one
genotype at one locus (can be 2, 4 or 6). If not provided, this is
determined from data.
ind.names
an optional character vector giving the individuals
names; if NULL, taken from rownames of X.
loc.names
an optional character vector giving the markers
names; if NULL, taken from colnames of X.
pop
an optional factor giving the population of each individual.
missing
can be NA, 0 or "mean". See details section.
x
a genind object
sep
a character used to separate two alleles
Value
an object of the class genind for df2genind;
a matrix of biallelic genotypes for genind2df
encoding
UTF-8
Details
There are 3 treatments for missing values:
- NA: kept as NA.
- 0: allelic frequencies are set to 0 on all alleles of the concerned
locus. Recommended for a PCA on compositionnal data.
- "mean": missing values are replaced by the mean frequency of the
corresponding allele, computed on the whole set of
individuals. Recommended for a centred PCA.