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次),每次存储函数输出,然后使用该输出启动下一个函数。
类似于(但只是自动化的):
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我该怎么做?
发布于 2015-10-30 08:32:01
像那样吗?
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])
}发布于 2015-10-30 08:43:06
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])
}https://stackoverflow.com/questions/33431406
复制相似问题