初步脚本如下
library(genetics)
test1 <-read.csv("test1.csv",header = T,row.names = 1)
test2 <-read.csv("test2.csv",header = T,row.names = 1)
pops <-length(test1)
LDD = as.data.frame(matrix(nrow=pops,ncol=6))
colnames(LDD) <- c( "pops", "D'", "Corr.", "X^2", "P-value", "n")
for (i in 1:43){
data1<- list(SS=test1[i,1], SR=test1[i,2], RR=test1[i,3], na=test1[i,4])
data2<- list(SS=test2[i,1], SR=test2[i,2], RR=test2[i,3], na=test2[i,4])
g1 <-genotype(c(rep("R/R",data1$RR),rep("R/S",data1$SR),rep("S/S",data1$SS),rep("NA",data1$na)))
g2 <-genotype(c(rep("R/R",data2$RR),rep("R/S",data2$SR),rep("S/S",data2$SS),rep("NA",data2$na)))
df <- makeGenotypes(data.frame(g1,g2))
LD(df)