by Verena Haunschmid
Since I have a cat tracker, I wanted to do some analysis of the behavior of my cats. I have shown how to do some of these things here.
Data Collection
The data was collected using the Tractive GPS Pet Tracker over a period of about one year from January 2014 to November 2014 (with breaks). From March to November I additionally took notes in an Excel sheet which cat was carrying the tracker.
Libraries you need
If you want to reproduce my example you need the following libraries:
- XML
- plyr
- xlsx
- devtools
- leaflet (installed via devtools::install_github(“rstudio/leaflet”))
Loading the data into R
There are some methods to read .gpx files in R, but since I just wanted to use it for this one specific file I created my own method:
readTrackingFile
library(XML)
library(plyr)
xmlfile
xmltop
tracking
function(x) {data.frame(x)
})
tracking
“time” = as.character(tracking$time
[seq(1, nrow(tracking), 2)]),
“lat” = tracking$.attrs[seq(1, nrow(tracking), 2)],
“lon” = tracking$.attrs[seq(2, nrow(tracking), 2)])
tracking$ele
tracking$lat
tracking$lon
time_pattern
tracking$time
tracking$min
message(paste(“read”, nrow(tracking), “tracking points”))
return(tracking)
}
Then I used this method to read the tracks:
track
And made a rudimentary plot to see where the data was:
# showed that some were far off
plot(track$lon, track$lat, pch=19, cex=0.5)
track 30,]
Since we also used our tracker to track our vacation, I had to …read more
Source:: r-bloggers.com