【发布时间】:2019-12-09 05:50:27
【问题描述】:
我插入了一个 for 循环:
for(j in 2:1036) {
nMatchingLoci = 0
for(i in 1:1) {
if(sampGeno[1,i]==FGMMdata[1,i,j] && sampGeno[2,i]==FGMMdata[2,i,j]) {
nMatchingLoci = nMatchingLoci + 1
}
}
if(nMatchingLoci==1) {
print(paste("!!! 1 locus match with entry number", j))
}
}
我的输出只是一个配置文件列表。我如何添加有多少?
列表在我的控制台中如下所示:
[1] "!!! 1 locus match with entry number 4"
[1] "!!! 1 locus match with entry number 7"
[1] "!!! 1 locus match with entry number 24"
[1] "!!! 1 locus match with entry number 44"
[1] "!!! 1 locus match with entry number 51"
[1] "!!! 1 locus match with entry number 53"
[1] "!!! 1 locus match with entry number 58"
[1] "!!! 1 locus match with entry number 63"
[1] "!!! 1 locus match with entry number 72"
等等……
【问题讨论】:
-
除了将 i 的值设置为 1 之外,您对 i 的 for 循环不会做任何事情。要么您不需要该 for 循环,只需将 i 设置为 1,要么您顺序有误。此外,假设您的 for 循环 i 在 1:1035 中运行(比如说)i,您现在可能会多次找到匹配项,使 nMatchingLoci 大于 1,这将导致声明您的 if 语句失败来一场比赛。
标签: r for-loop if-statement rstudio