lundi 9 décembre 2019

Is there a way to add the number of outputs from a for loop in R?

I inserted a for loop:

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))
 }
  } 

And my output is just a list of profiles. How do I add how many are there?

The list looks like this in my console:

[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"

and so on...

Aucun commentaire:

Enregistrer un commentaire