-2
我是一個r編程的初學者,我試圖對25個細胞進行採樣,它們之間用最小距離「d」分隔。 我有一個在r編程中滿足距離條件的樣本N個細胞
b=c() # vector to store the selected cells
b[1]=sample(a,1) # randomly sampling the first cell from my landscape
x=c()
for (i in 1:24){
b2=sample(a,1) #propose a candidate cell
for(j in 1:i){
if (DIJ[b[j],b2]>=d){ #check if the distance between the proposed and ALL the
x[i]=1 chosen
#cells meets the distance, where DIJ is a distance matrix
} assign 1 if it does, 0 otherwise
else{x[i]=0
}}
while(sum(x)==i){ #If the sum equals i, then the proposed meets the requirement
b2=b[i+1] against all the cells, otherwise start again with a new
}} proposal
我會很感激的建議,使這片代碼工作。
亞歷
請提供[再現的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。請提供 – Thomas
樣品數據! – Metrics
採樣一個單元。刪除距採樣單元太近的單元。樣品第二個單元。重複最後兩步25次。 –