The stu.csv contains more than 850,000 rows and 3 columns. This code is as follows, but it has been ruing for three days. how to speed and rewrite this code? Thank you.
stu<-read.table("stu.csv",header=T,sep=",");
## stu has more than 850,000 rows and 3 columns.
m<-nrow(stu);
distance<-0;
for (i in 1:(m-1))
{
for (j in (i+1):m)
{
dlon = stu[j,2] - stu[i,2];
dlat = stu[j,3] - stu[i,3];
a = (sin(dlat/2))^2 + cos(stu[i,3]) * cos(stu[j,3]) * (sin(dlon/2))^2;
c = 2 * atan2( sqrt(a), sqrt(1-a) );
distance <-distance+6371000 * c;
}
}
distance
