首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何存储函数的输出,并将存储的输出作为下一个输入,并将此过程重复特定次数

如何存储函数的输出,并将存储的输出作为下一个输入,并将此过程重复特定次数
EN

Stack Overflow用户
提问于 2015-10-30 08:16:35
回答 2查看 163关注 0票数 1
代码语言:javascript
复制
require(geosphere)

x<-c(18.25721,18.25763)
y<-c(44.69540,44.69539)
# The coordinates
coords<-cbind(x,y)
# The direction
Bearing<-c(92.59359, 80.56905)
# The length
len<-c(33.19121, 36.66707)

我想要对这些数据做的是,多次使用来自destPoint包的geosphere函数(5次),每次存储函数输出,然后使用该输出启动下一个函数。

类似于(但只是自动化的):

代码语言:javascript
复制
out1<-destPoint(coords[1,],Bearing[1],len[1])
# out1
#           lon      lat
#      [1,] 18.25763 44.69539
out2<-destPoint(out1,Bearing[1],len[1])
and so on

我该怎么做?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-30 08:32:01

像那样吗?

代码语言:javascript
复制
numberOfIterations = 10 #Change That as needed 

intermediateOutput = list()
intermediateOutput[[1]] = destPoint(coords[1,],Bearing[1],len[1])

for(i in 2:numberOfIterations) {
  intermediateOutput[[i]] = destPoint(intermediateOutput[[i-1]],Bearing[1],len[1])
}
票数 2
EN

Stack Overflow用户

发布于 2015-10-30 08:43:06

代码语言:javascript
复制
out <- list()
out[[1]] <- destPoint(coords[1,],Bearing[1],len[1])

for(i in 2:5) {
out[[i]] <- destPoint(out[[i-1]],Bearing[1],len[1])
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33431406

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档