Learn R Programming

adegenet (version 1.1-1)

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.

Usage

df2genind(X, ncode=NULL, ind.names=NULL, loc.names=NULL, pop=NULL,
 missing=NA)
genind2df(x,pop=NULL, sep="")

Arguments

X
a matrix or a data.frame (see decription)
ncode
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.

See Also

import2genind, read.genetix, read.fstat, read.structure

Examples

Run this code
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)

Run the code above in your browser using DataLab