Normalise a dataframe and check for columns correspondance to be able to use it as an input to create a Ped object.
Usage
norm_rel(rel_df, na_strings = c("NA", ""), missid = NA_character_)
Arguments
- rel_df
A data.frame with the special relationships between individuals. See
Rel()
for more informations. The minimum columns required areid1
,id2
andcode
. Thefamid
column can also be used to specify the family of the individuals. If a matrix is given, the columns needs to be ordered asid1
,id2
,code
andfamid
. The code values are:1
= Monozygotic twin2
= Dizygotic twin3
= twin of unknown zygosity4
= Spouse
The value relation code recognized by the function are the one defined by the
rel_code_to_factor()
function.- na_strings
Vector of strings to be considered as NA values.
- missid
A character vector with the missing values identifiers. All the id, dadid and momid corresponding to those values will be set to
NA_character_
.
Details
The famid
column, if provided, will be merged to the
ids field separated by an underscore using the
upd_famid()
function.
The code
column will be transformed with the
rel_code_to_factor()
.
Multiple test are done and errors are checked.
A number of checks are done to ensure the dataframe is correct:
Examples
df <- data.frame(
id1 = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
id2 = c(2, 3, 4, 5, 6, 7, 8, 9, 10, 1),
code = c("MZ twin", "DZ twin", "UZ twin", "Spouse",
1, 2, 3, 4, "MzTwin", "sp oUse"),
famid = c(1, 1, 1, 1, 1, 1, 1, 2, 2, 2)
)
norm_rel(df)
#> id1 id2 code famid error
#> 1 1_1 1_2 MZ twin 1 <NA>
#> 2 1_2 1_3 DZ twin 1 <NA>
#> 3 1_3 1_4 UZ twin 1 <NA>
#> 4 1_4 1_5 Spouse 1 <NA>
#> 5 1_5 1_6 MZ twin 1 <NA>
#> 6 1_6 1_7 DZ twin 1 <NA>
#> 7 1_7 1_8 UZ twin 1 <NA>
#> 8 2_8 2_9 Spouse 2 <NA>
#> 9 2_9 2_10 MZ twin 2 <NA>
#> 10 2_10 2_1 Spouse 2 <NA>