if statement - How can I tell a for loop in R to regenerate a sample if the sample contains a certain pair of species? -


i creating 1000 random communities (vectors) species pool of 128 operations applied community , stored in new vector. simplicity, have been practicing writing code using 10 random communities species pool of 20. problem there couple of pairs of species such if 1 of pairs generated in random community, need community thrown out , new 1 regenerated. have been able code if pair found in community community(vector) labeled na. know how tell loop skip vector using "next" command. both of these options, not of communities needing.

here code using na option, again ends shorting me communities.

c<-c(1:20) d<-numeric(10) x<- numeric(5) for(i in 1:10){   x<-sample(c, size=5, replace = false)   if("10" %in% x & "11" %in% x) x=na else x=x   if("1" %in% x & "2" %in% x) x=na else x=x   print(x)   d[i]<-sum(x)   } print(d) 

this result looks like.

[1]  5  1  7  3 14 [1] 20  8  3 18 17 [1] na [1] na [1] 4 7 1 5 3 [1] 16  1 11  3 12 [1] 14  3  8 10 15 [1]  7  6 18  3 17 [1]  6  5  7  3 20 [1] 16 14 17  7  9 > print(d)  [1] 30 66 na na 20 43 50 51 41 63 

thanks much!


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -