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
我该怎么做?
答案 0 :(得分:2)
那样的东西?
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])
}
答案 1 :(得分:1)
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])
}