a <- cbind(c(1,5,55,31),c(3,7,20,22))
b <- cbind(c(4,2,8,65),c(50,-90,20,32))
pointDistance(c(0, 0), c(1, 1), type='Euclidean')
pointDistance(c(0, 0), c(1, 1), type='GreatCircle')
pointDistance(c(0, 0), a, type='GreatCircle')
pointDistance(a, b, type='GreatCircle')
#Make a distance matrix (dist object)
dst <- matrix(nrow=4,ncol=4)
for (i in 1:4){dst[,i] <- pointDistance(a[i,],a, type='GreatCircle')}
dst <- as.dist(dst)
#The same as above, but avoiding the loop
dst <- pointDistance(a[rep(1:4,times=4),],a[rep(1:4,each=4),], type='GreatCircle')
dst <- as.dist(matrix(dst,ncol=4))
Run the code above in your browser using DataLab