An accessor is a function that allows to interact with slots of an
object in a convenient way. Several accessors are available for genind or
genpop objects. The operator "\$" and "\$<-" are used to
access the slots, being equivalent to "@" and "@<-".
The operator "[" is a flexible way to subset data by individuals,
populations, alleles, and loci. When using a matrix-like syntax,
subsetting will apply to the dimensios of the @tab slot. In addition,
pop can be used to indicate
subsets of loci and populations. The argument
drop is a logical
indicating if alleles becoming non-polymorphic in a new dataset should
be removed (default: FALSE). Examples:
"obj[i,j]" returns "obj" with a subset 'i' of individuals and 'j' of
"obj[1:10,]" returns an object with only the first 10 genotypes (if
"obj" is a genind) or the first 10 populations (if
"obj" is a genpop)
"obj[1:10, 5:10]" returns an object keeping the first 10 entities and
the alleles 5 to 10.
"obj[loc=c(1,3)]" returns an object keeping only the 1st and 3rd
locNames(obj) as reference; logicals, or named loci
also work; this overrides other subsetting of alleles.
"obj[pop=2:4]" returns an object keeping only individuals from the
populations 2, 3 and 4, using
popNames(obj) as reference;
logicals, or named populations also work; this overrides other
subsetting of individuals.
"obj[i=1:2, drop=TRUE]" returns an object keeping only the first
two individuals (or populations), dropping the alleles no longer
present in the data.
treatOther handles the treatment of objects in the
@other slot (see details). The argument
drop can be set
to TRUE to drop alleles that are no longer represented in the subset.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
nInd(x, ...) nLoc(x, ...) nAll(x, onlyObserved = FALSE, ...) nPop(x, ...) pop(x) indNames(x, ...) ## S4 method for signature 'genind' indNames(x, ...) locNames(x, ...) ## S4 method for signature 'genind' locNames(x, withAlleles=FALSE, ...) ## S4 method for signature 'genpop' locNames(x, withAlleles=FALSE, ...) popNames(x, ...) ## S4 method for signature 'genind' popNames(x, ...) popNames(x, ...) ## S4 method for signature 'genpop' popNames(x, ...) ploidy(x, ...) ## S4 method for signature 'genind' ploidy(x, ...) ## S4 method for signature 'genpop' ploidy(x, ...) ## S4 method for signature 'genind' other(x, ...) ## S4 method for signature 'genpop' other(x, ...)
a genind or a genpop object.
a logical indicating whether the allele count should
also include the alleles with onlyObserved columns in the matrix. Defaults
a logical indicating whether the result should be of the form [locus name].[allele name], instead of [locus name].
further arguments to be passed to other methods (currently not used).
The "[" operator can treat elements in the
@other slot as
well. For instance, if
obj@other$xy contains spatial
obj[1:3, ]@other$xy will contain the spatial
coordinates of the genotypes (or population) 1,2 and 3. This is
handled through the argument
treatOther, a logical defaulting
to TRUE. If set to FALSE, the
@other returned unmodified.
Note that only matrix-like, vector-like and lists can be proceeded in
@other. Other kind of objects will issue a warning an be
returned as they are, unless the argument
quiet is left to
TRUE, its default value.
drop argument can be set to TRUE to retain only alleles
that are present in the subset. To achieve better control of
polymorphism of the data, see
nAll() reflects the number of columns per locus present in the current
gen object. If
onlyObserved = TRUE, then the number of columns with at
least one non-missing allele is shown.
A genind or genpop object.
returns the number of individuals in the
returns the number of loci
returns the number of observed alleles in each locus
returns the number of populations
returns a factor assigning individuals to populations.
replacement method for the
@pop slot of an
returns the names of populations.
sets the names of populations using a vector of
returns the names of individuals.
sets the names of individuals using a vector of
returns the names of markers and/or alleles.
sets the names of markers using a vector of
returns a factor that defines which locus each column of the
@tab slot belongs to
returns the ploidy of the data.
sets the ploidy of the data using an integer.
returns the alleles of each locus.
sets the alleles of each locus using a list with one character vector for each locus.
returns the content of the
(misc. information); returns
NULL if the slot is onlyObserved or of
sets the content of the
(misc. information); the provided value needs to be a list; it
not, provided value will be stored within a list.
Thibaut Jombart email@example.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
data(nancycats) nancycats pop(nancycats) # get the populations indNames(nancycats) # get the labels of individuals locNames(nancycats) # get the labels of the loci alleles(nancycats) # get the alleles nAll(nancycats) # count the number of alleles head(tab(nancycats)) # get allele counts # get allele frequencies, replace NAs head(tab(nancycats, freq = TRUE, NA.method = "mean")) # let's isolate populations 4 and 8 popNames(nancycats) obj <- nancycats[pop=c(4, 8)] obj popNames(obj) pop(obj) nAll(obj, onlyObserved = TRUE) # count number of alleles among these two populations nAll(obj) # count number of columns in the data all(nAll(obj, onlyObserved = TRUE) == lengths(alleles(obj))) # will be FALSE since drop = FALSE all(nAll(obj) == lengths(alleles(obj))) # will be FALSE since drop = FALSE # let's isolate two markers, fca23 and fca90 locNames(nancycats) obj <- nancycats[loc=c("fca23","fca90")] obj locNames(obj) # illustrate pop obj <- nancycats[sample(1:100, 10)] pop(obj) pop(obj) <- rep(c('b', 'a'), each = 5) pop(obj) # illustrate locNames locNames(obj) locNames(obj, withAlleles = TRUE) locNames(obj) <- "newLocus" locNames(obj) locNames(obj, withAlleles=TRUE) # illustrate how 'other' slot is handled data(sim2pop) nInd(sim2pop) other(sim2pop[1:6]) # xy is subsetted automatically other(sim2pop[1:6, treatOther=FALSE]) # xy is left as is
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.