So, I have a large pedigree consisting of individuals, parents, year of births and average year of birth for the individuals offspring. To be clarify with an example: for Individual 5 the year of birth is 1900. This is not possible because its parents are born in 1975 and 1977. Individual 5 also has offspring with year of birth. A common method to "fix" missing or faulty year of birth data is to subtract the generation interval from average year of birth from the offspring. So, for individual 5, average year of birth of the offspring is 1983, so 1983 - 5 = 1978. I tried to code it using the IF function, but it did not work as I got two errors (pasted below). Would case_when and mutate work better?
Indiv <- c(1:10)
Mother <- c(NA, NA, NA, 2, 3, 3, 6, 3, 8, 8)
Father <- c(NA, NA, NA, 1, 1, 1, 5, 4, 4, 9)
YOB <- c(1975, 1975, 1977, 1980, 1900, 1982, 1983, NA, 1988, 1993)
AvgYOBOff <- c(1954, 1981, 1943, 1988, 1983, 1983, NA, 1990.5, 1993, NA)
df <- data.frame(Indiv, Mother, Father, YOB, AvgYOBOff)
L = 5 #generation interval of 5 years
if(df$YOB < df$YOB[match(df$Mother, df$Indiv)] & df$YOB[match(df$Father, df$Indiv)]){
mutate(df, YOB = AvgYOBOff - L)
}
Error in if (df$YOB < df$YOB[match(df$Mother, df$Indiv)] & df$YOB[match(df$Father, :
missing value where TRUE/FALSE needed
In addition: Warning message:
In if (df$YOB < df$YOB[match(df$Mother, df$Indiv)] & df$YOB[match(df$Father, :
the condition has length > 1 and only the first element will be used
Aucun commentaire:
Enregistrer un commentaire