-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次。 –