as.data.frame.gtypes: Convert 'gtypes' to data.frame or matrix

as.data.frame.gtypesR Documentation

Convert gtypes to data.frame or matrix

Description

Create a formatted data.frame or matrix from a gtypes object.

Usage

## S4 method for signature 'gtypes'
as.data.frame(
  x,
  one.col = FALSE,
  sep = "/",
  ids = TRUE,
  strata = TRUE,
  sort.alleles = TRUE,
  coded.snps = FALSE,
  ref.allele = NULL,
  ...
)

## S4 method for signature 'gtypes'
as.matrix(
  x,
  one.col = FALSE,
  sep = "/",
  ids = TRUE,
  strata = TRUE,
  sort.alleles = TRUE,
  ...
)

Arguments

x

a gtypes object.

one.col

logical. If TRUE, then result has one column per locus.

sep

character to use to separate alleles if one.col is TRUE.

ids

logical. include a column for individual identifiers (ids)?

strata

logical. include a column for current statification (strata)?

sort.alleles

logical. for non-haploid objects, should alleles be sorted in genotypes or left in original order? (only takes affect if one.col = TRUE)

coded.snps

return diploid SNPs coded as 0 (reference allele homozygote), 1 (heterozygote), or 2 (alternate allele homozygote). If this is 'TRUE', the data is diploid, and all loci are biallelic, a data frame of coded genotypes will be returned with one column per locus.

ref.allele

an optional vector of reference alleles for each SNP. Only used if 'coded.snps = TRUE'. If provided, it must be at least as long as there are biallelic SNPs in g. If named, the names must match those of all loci in g. If set to 'NULL' (default) the major allele at each SNP is used as the reference.

...

additional arguments to be passed to or from methods.

Value

A data.frame or matrix with one row per individual.

Author(s)

Eric Archer eric.archer@noaa.gov

See Also

df2gtypes as.matrix

Examples

data(msats.g)

# with defaults (alleles in multiple columns, with ids and stratification)
df <- as.data.frame(msats.g)
str(df)

# one column per locus
onecol.df <- as.data.frame(msats.g, one.col = TRUE)
str(onecol.df)

# just the genotypes
genotypes.df <- as.data.frame(msats.g, one.col = TRUE, ids = FALSE, strata = FALSE)
str(genotypes.df)

# as a matrix instead
genotypes.mat <- as.matrix(msats.g)
str(genotypes.mat)


EricArcher/strataG documentation built on Feb. 12, 2023, 4:11 a.m.