Learn R Programming

adegenet (version 1.4-2)

na.replace-methods: Replace missing values (NA) from an object

Description

The generic function na.replace replaces NA in an object by appropriate values as defined by the argument method. Methods are defined for genind and genpop objects.

Usage

## S3 method for class 'genind':
na.replace(x,method, quiet=FALSE)
## S3 method for class 'genpop':
na.replace(x,method, quiet=FALSE)

Arguments

x
a genind and genpop object
method
a character string: can be "0" or "mean" for genind objects, and "0" or "chi2" for genpop objects.
quiet
logical stating whether a message should be printed (TRUE,default) or not (FALSE).

Value

  • A genind and genpop object without missing values.

Details

The argument "method" have the following effects: - "0": missing values are set to "0". An entity (individual or population) that is not type on a locus has zeros for all alleles of that locus. - "mean": missing values are set to the mean of the concerned allele, computed on all available observations (without distinction of population). - "chi2": if a population is not typed for a marker, the corresponding count is set to that of a theoretical count in of a Chi-squared test. This is obtained by the product of the sums of both margins divided by the total number of alleles.

Examples

Run this code
data(nancycats)

obj1 <- genind2genpop(nancycats)
# note missing data in this summary
summary(obj1)

# NA are all in pop 17 and marker fca45
which(is.na(obj1$tab),TRUE)
truenames(obj1)[17,]

# replace missing values
obj2 <- na.replace(obj1,"chi2")
obj2$loc.names

# missing values where replaced
truenames(obj2)[,obj2$loc.fac=="L4"]

Run the code above in your browser using DataLab