0

I have a dataset with id, lat, lon and time, where each trip has a unique id.

When I try to use mutate with the distanceGPS function in the AnalyzeGPS package and group by trip using this code:

gps%>%group_by(id) %>% 
  arrange(time) %>%mutate(d <- c(0, 
  distanceGPS(lat1 = lat[1:(n()-1)], 
              lon1 = lon[1:(n()-1)], 
              lat2 = lat[2:n()], 
              lon2 = lon[2:n()]
              )
              )
  )​

I get this error: Error Colum ...<-NULL must be lenght 1(group size), not 3

This works:

d <- distanceGPS(lat1 = gps$lat[1:(length(gps$lat) - 1)], 
                 lon1 = gps$lon[1:(length(gps$lon) -1)], 
                 lat2 = gps$lat[2:length(gps$lat)], 
                 lon2 = gps$lon[2:length(gps$lon)])
trips$d <- c(0, d)​

... but it just has one trip with multiple points.

  • 1
    How is it "Not working"? What is your input data? What for do you expect your output to be? What are you getting instead? – Spacedman Jul 26 at 20:53
  • 1
    Where does the analyzeGPS package come from? Its not on CRAN. – Spacedman Jul 26 at 20:54
  • Thanks @Spacedman , in fact not working means what i did is not correct, I think my probel is with the code itself, not with the library analyseGPS link What I actually need is to use an operation inside mutate (Here calculating the distance between each consecutive points for each trip) – pochi Aug 2 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.