Skip to contents

This function converts genotype data between character ("A", "H", "B") and numeric (0, 1, 2) formats. The conversion direction is controlled by the numeric_output argument.

Usage

formater(geno, numeric_output = TRUE)

Arguments

geno

A data frame containing genotype data, where values are either "A", "H", "B" or 0, 1, 2. The function assumes the dataset consists entirely of genotypic or numeric values.

numeric_output

Logical. If TRUE, converts "A"0, "H"1, "B"2. If FALSE, converts 0"A", 1"H", 2"B". Default is TRUE.

Value

A data frame with the same structure as geno, but with values converted based on the numeric_output parameter.

Details

  • Preserves NA values during conversion.

  • Unexpected values (anything other than "A", "H", "B", 0, 1, 2) are converted to NA.

Examples

# Example genotype data in character format
geno_char <- data.frame(
  Marker1 = c("A", "H", "B"),
  Marker2 = c("B", "A", "H")
)

# Convert character to numeric format
geno_numeric <- formater(geno_char, numeric_output = TRUE)
print(geno_numeric)
#>   Marker1 Marker2
#> 1       0       2
#> 2       1       0
#> 3       2       1

# Convert numeric format back to character format
geno_char_reversed <- formater(geno_numeric, numeric_output = FALSE)
print(geno_char_reversed)
#>   Marker1 Marker2
#> 1       A       B
#> 2       H       A
#> 3       B       H