DT2Mat_freqs | R Documentation |
Takes a data table of allele frequencies in long format and converts it into
a matrix in wide format (loci in columns and populations in rows). The reverse
can also be done. See also DT2Mat_genos
for converting matrix of genotypes.
DT2Mat_freqs(
dat,
popCol = "POP",
locusCol = "LOCUS",
freqCol = "FREQ",
flip = FALSE
)
dat |
Data table or Matrix: The object to transform. If this is a long data table of allele frequencies, then three columns are required:
The population pool column serves as the pivot point to convert the long data table into a wide matrix.
If converting from a frequency matrix to a data table, see argument |
popCol |
Character: The column name with the population information. Default is 'POP'. |
locusCol |
Character: The column name with the locus information. Default is 'LOCUS'. |
freqCol |
Character: The column name with the Ref allele frequency. Default is 'FREQ'. |
flip |
Logical: Instead of converting a (long) data table to a (wide) matrix,
should a (wide) matrix be converted into a (long) data table? Default = |
When flip=FALSE
, converts a data table into a frequency matrix. When
flip=TRUE
, converts a matrix into a data table with three columns: (1) $POP
,
the population ID (as for pool-seq data); (2) $LOCUS
, the locus ID; and (3) FREQ
,
the Ref allele frequency.
data(data_PoolFreqs)
# Convert a long data table to a wide matrix
freqMat <- DT2Mat_freqs(
dat=data_PoolFreqs,
popCol='POOL',
locusCol='LOCUS',
freqCol='FREQ',
flip=FALSE)
freqMat
# Convert a wide matrix back to a data table
freqDT <- DT2Mat_freqs(
freqMat,
popCol='POOL',
locusCol='LOCUS',
freqCol='FREQ',
flip=TRUE)
freqDT
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.