Learn R Programming

trip (version 1.1-1)

trip: Function to handle animal track data, organized as "trip"s

Description

Extend the basic functionality of a Spatial data frame by specifying the data columns that define the "TimeOrdered" quality of the records.

Usage

trip(obj, TORnames)

Arguments

obj
A SpatialPointsDataFrame, containing at least two columns with the DateTime and ID data as per TORnames
TORnames
Either an object of TimeOrderedRecords, or a 2-element character vector specifying the DateTime and ID column of obj

Value

  • A trip object, with the usual slots of a SpatialPointsDataFrame and the added TimeOrderedRecords. For the most part this can be treated as a data.frame with Spatial coordinates.

See Also

speedfilter, and tripGrid for simple(istic) speed filtering and spatial time spent gridding.

Examples

Run this code
d <- data.frame(x = 1:10, y = rnorm(10), tms = Sys.time() + 1:10, id = gl(2, 5))
coordinates(d) <- ~x+y
tr <- trip(d, c("tms", "id"))

## a simple example with the common fixes required for basic track data

dat <- read.csv("trackfile.csv")
names(dat)  ## e.g. [1] "long" "lat"  "seal"  "date"    "local"     "lq"
library(sp)
coordinates(dat) <- c("long", "lat")

## date/times may be in a particular time zone, please check
dat$gmt <- as.POSIXct(strptime(paste(dat$date, dat$local),
                      "

## if there are problems in the data, this will error
tr <- trip(dat, c("gmt", "seal"))


## the following code tries to fix common problems

## remove completely-duplicated rows
dat <- dat[!duplicated(dat), ]

## order the rows by seal, then by time
dat <- dat[order(dat$seal, dat$gmt), ]

## fudge duplicated times
dat$gmt <- adjust.duplicateTimes(dat$gmt, dat$seal)


## finally, convert to Spatial and create trip object
coordinates(dat) <- c("long", "lat")
tr <- trip(dat, c("gmt", "seal"))

Run the code above in your browser using DataLab