0
무작위 도보 루프에서는 단계 번호를 변수로 사용하는 함수를 통합해야합니다.랜덤 워크에 스텝 카운터를 포함하려면 어떻게해야합니까?
랜덤 워크 중에 R이 스텝 번호를 생성하도록하려면 (루프 카운터가 더 좋은 용어 일 수 있습니다)?
내가 바로 내가 현재 내 랜덤 워크 코드는 참고 더미 코드 step.num
이이 코드의 끝에 그것을 필요했다 for 루프 후
walkW <- function(n.times=125,
xlim=c(524058,542800),
ylim=c(2799758,2818500),
start=c(542800,2815550),
stepsize=c(4000,4000)) {
plot(c(0,0),type="n",xlim=xlim,ylim=ylim,
xlab="Easting",ylab="Northing",col="white",col.lab="white")#arena
x <- start[1]
y <- start[2]
steps <- 1/c(1,2,4,8,12,16)
steps.y <- c(steps,-steps,0)
steps.x <- c(steps[c(1,5,6)],-steps,0)
points(x,y,pch=16,col="green",cex=1)
for (i in 1:n.times) {
repeat {
xi <- stepsize[1]*sample(steps.x,1)
yi <- stepsize[2]*sample(steps.y,1)
newx <- x+xi
newy <- y+yi
if (newx>xlim[1] && newx<xlim[2] &&
newy>ylim[1] && newy<ylim[2]) break
}
lines(c(x,newx),c(y,newy),col="white")
x <- newx
y <- newy
}
step.num<-(your magical step counter function) #I need the step counter here
}
set.seed(101)
walkW(s)
'all' 기능을 원할 수도 있습니다. 휴식 조건은 (모든 (newx> xlim [1], newx ylim [1], newy
Gregor
환상적인 당신. 나는 실제로 똑같은 대답을주기 위해 실제로 다시 터졌다. 마법이 x = y처럼 단순 할 때 항상 좋습니다. 무리 감사! – Jesse001