-1
R에서 의사 코드를 변환하면 함수 바인딩이 정의 된 상태에서 모든 바인딩이 고정됩니다. R에있는 재귀 함수 작성
lastfunction <- function(inputx) {rep(0,length(inputx))}
i<-1
while(i<=2){
afunction <- function(inputx) {i*inputx} #freeze all variable used in the body
lastfunction <- lastfunction + afunction #and of course the label "afunction" as well
i<-i+1
}
#then apply to some data
lastfunction(c(0,1,5,6))
나는 환경 보았지만 (환경 중첩?)
당신은 더 적은 R처럼 많이 보이는 무언가에 의사 코드를 다시 작성할 수 있습니까? 당신은 두 가지 기능을 추가하고 있으며, 당신이 원하는 것을 이해하지 못합니다. – Spacedman
그냥 미주에 :'리콜 '을보세요. –