나는 이것이 plink FAM 형식으로 추측하고, 어떤 사람은 아버지 나 어머니 누락, 모두 다음 할 수없는 경우에 우리는 부모 중 적어도 하나가 개인 누락 부모를 추가 할 부모를 추가하지 마십시오.
# dummy fam data with missing parents
df1 <- read.table(text = "FID IID Father Mother Sex
1 1 0 2 1
1 2 0 0 2
1 3 0 2 1
1 4 0 2 2
2 1 3 0 1
2 2 3 0 2
2 3 0 0 1
3 1 0 0 1
4 1 0 0 1
4 2 0 0 2
4 3 1 2 2
4 4 1 2 2
", header = TRUE,
colClasses = "character")
더미 데이터에 대한 참고 :
- FID == 1은 아버지가없는
- FID == 2는 어머니가 누락
- FID == 3와 한 개인 가족 어떤 부모
- FID == 4 실종 부모
작업 없다, 아버지 또는 그들 중 하나가 누락 된 경우에만 어머니 누락 추가합니다. 즉, 아버지 == 0 및 어머니 == 0이 모두 누락 된 경우 부모를 추가하지 마십시오.
library(dplyr) # using dplyr for explicity of steps.
# update 0 to IID for missing Father and Mother with suffix f and m
df1 <-
df1 %>%
mutate(
FatherNew = if_else(Father == "0" & Mother != "0", paste0(Mother, "f", IID), Father),
MotherNew = if_else(Mother == "0" & Father != "0", paste0(Father, "m", IID), Mother))
# add missing Fathers
missingFather <- df1 %>%
filter(
FatherNew != "0" &
MotherNew != "0" &
!FatherNew %in% df1$IID) %>%
transmute(
FID = FID,
IID = FatherNew,
Father = "0",
Mother = "0",
Sex = "1") %>%
unique
# add missing Mothers
missingMother <- df1 %>%
filter(
FatherNew != "0" &
MotherNew != "0" &
!MotherNew %in% df1$IID) %>%
transmute(
FID = FID,
IID = MotherNew,
Father = "0",
Mother = "0",
Sex = "2") %>%
unique
# update new Father/Mother IDs
res <- df1 %>%
transmute(
FID = FID,
IID = IID,
Father = FatherNew,
Mother = MotherNew,
Sex = Sex)
# add missing Fathers/Mothers as new rows, and sort
res <- rbind(
res,
missingFather,
missingMother) %>%
arrange(FID, IID)
결과, 출력
res
# FID IID Father Mother Sex
# 1 1 1 2f1 2 1
# 2 1 2 0 0 2
# 3 1 2f1 0 0 1
# 4 1 2f3 0 0 1
# 5 1 2f4 0 0 1
# 6 1 3 2f3 2 1
# 7 1 4 2f4 2 2
# 8 2 1 3 3m1 1
# 9 2 2 3 3m2 2
# 10 2 3 0 0 1
# 11 2 3m1 0 0 2
# 12 2 3m2 0 0 2
# 13 3 1 0 0 1
# 14 4 1 0 0 1
# 15 4 2 0 0 2
# 16 4 3 1 2 2
# 17 4 4 1 2 2
정말 환상적입니다. 내 90 % 문제가 해결되었습니다. 마지막 질문 하나만 남았습니다. 아버지 나 어머니 중 일부는 1 명이 넘었고, 나는 그들을 위해 별도의 ID를 원합니다. 예를 들어 위의 예에서 아버지 '3'이 두 번 나오므로 엄마가 3m1, 3m2 ..... 그리고 같은 fasion에서 IID가 조정되어야합니다. 내가 할 수 있다는 것을 알고 계십니까? – user2808642
@ user2808642 그렇다면 형제는 같은 아버지 (3 명)와 2 명의 다른 어머니 (3m1 및 3m2) 출신이라고 말하고 있습니까? – zx8754
@ user2808642 내 더미 데이터를 게시물에 복사하고 예상 출력을 추가 할 수 있다면 좋을 것입니다. – zx8754