Kinship2谱系构造:错误“缺少需要真或假的值”

时间:2019-07-18 14:42:23

标签: r if-statement error-handling

我正在尝试与亲属关系2建立一个谱系,稍后再计划绘制。但是我一直收到错误消息

  

“如果(min(sex)== 0)性别<-性别+ 1:     缺少需要TRUE / FALSE的值”。

我已经尝试在函数中添加此语句,结果产生了新错误

library(kinship2)
dumdog<-read.csv("Dummydogdatakinship.csv")


colnames(dumdog)[1]<-"id"
colnames(dumdog)[2]<-"fatherid"
colnames(dumdog)[3]<-"motherid"

dogped<-with(dumdog, pedigree(id, fatherid, motherid,sex))
#this produces error : if min... true/false needed, so I tried this

dogped<-with(dumdog, pedigree(id, fatherid, motherid, sex)){
  if(min(sex)==0){
    sex<-sex + 1
  }
}
#this produces error "Error: unexpected '}' in '}'"

#but I also knew that I had no 0 values in my column sex (only 1 for male 
and 2 for female) so this if statement will produce an NA

#so i tried something like this:
dogped<-with(dumdog, pedigree(id, fatherid, motherid, sex)){
 if(is.na(min(sex)==0)){
    sex<-sex + 0
  }
}
#but I got the same "}" error as above and my pedigree dataframe still 
wasn't created.

在使用其他数据集之前,我曾遇到过这个问题,最终我使用了一个不同的程序包来制作较小的血统书。但是我需要在谱系中至少显示20代才能进行分析,所以我真的希望我能使它工作。您可以从kinship2包中使用一个minnbreast示例数据集来执行此操作,但是它不会产生上面的错误代码,因此我不确定这会有所帮助。

0 个答案:

没有答案