df2genind {adegenet} | R Documentation |
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 characters coding alleles with or without
separator. If no separator is used, the function tries to find how
many characters code each genotypes at a locus, but it is safer to state it
(ncode
argument). Uncomplete strings are filled with "0" at the
begining.
The function genind2df
converts a genind back to
such a data.frame.
df2genind(X, sep=NULL, ncode=NULL, ind.names=NULL, loc.names=NULL, pop=NULL, missing=NA, ploidy=2) genind2df(x,pop=NULL, sep="", usepop=TRUE)
X |
a matrix or a data.frame (see decription) |
sep |
a character string separating alleles. See details. |
ncode |
an optional integer giving the number of characters used for coding one genotype at one locus. 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. |
ploidy |
an integer indicating the degree of ploidy of the genotypes. |
x |
a genind object |
usepop |
a logical stating whether the population (argument pop
or x@pop should be used (TRUE, default) or not (FALSE). |
=== 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.
=== Details for the sep
argument ===
this character is directly used in reguar expressions like
gsub
, and thus require some characters to be preceeded by
double backslashes. For instance, "/" works but "|" must be coded as "\\|".
an object of the class genind for df2genind
;
a matrix of biallelic genotypes for genind2df
Thibaut Jombart jombart@biomserv.univ-lyon1.fr
import2genind
, read.genetix
,
read.fstat
, read.structure
df <- data.frame(loc1=c("11","11","12","32"), loc2=c(NA,"34","55","15"),loc3=c("22","22","21","22")) row.names(df) <- .genlab("geontype",4) df obj <- df2genind(df) obj truenames(obj) genind2df(obj)