Skip to contents

This helper function removes specified parental and F1 columns from a genotype dataset.

Usage

drop_parents(y, parent1 = "P1", parent2 = "P2", F1 = NULL)

Arguments

y

A data frame where individuals (including parents and F1s) are columns.

parent1

Character. The name of the first parent column to be removed. Default is "P1".

parent2

Character. The name of the second parent column to be removed. Default is "P2".

F1

(Optional) Character. The name of the F1 hybrid column to be removed. Default is NULL.

Value

A data frame with the specified parent and F1 columns removed.

Details

  • y must be coercible to a data frame.

  • Checks if the specified columns exist before attempting to drop them.

  • Only removes columns that are present in the data frame.

  • Preserves all other columns and their structure.

  • If multiple F1s are present they can be declared using the c() function

Examples

# Example dataset
geno_data <- data.frame(
  Marker1 = c(0, 1, 2),
  P1 = c(0, 0, 0),
  P2 = c(2, 2, 2),
  F1 = c(1, 1, 1),
  Ind1 = c(0, 1, 2),
  Ind2 = c(2, 0, 1)
)

# Drop parents P1 and P2
filtered_data <- drop_parents(geno_data)
print(filtered_data)
#>   Marker1 F1 Ind1 Ind2
#> 1       0  1    0    2
#> 2       1  1    1    0
#> 3       2  1    2    1

# Drop parents and F1
filtered_data_f1 <- drop_parents(geno_data, F1 = "F1")
print(filtered_data_f1)
#>   Marker1 Ind1 Ind2
#> 1       0    0    2
#> 2       1    1    0
#> 3       2    2    1

# Example dataset2
geno_data2 <- data.frame(
  Marker1 = c(0, 1, 2),
  P1 = c(0, 0, 0),
  P2 = c(2, 2, 2),
  F1a = c(1, 1, 1),
  F1b = c(1, 1, 1),
  Ind1 = c(0, 1, 2),
  Ind2 = c(2, 0, 1)
)


# Drop parents and multiple F1s
filtered_data_f1 <- drop_parents(geno_data, F1 = c("F1a", "F1b"))
print(filtered_data_f1)
#>   Marker1 F1 Ind1 Ind2
#> 1       0  1    0    2
#> 2       1  1    1    0
#> 3       2  1    2    1