Title: | Data Frame Class for Tracking Data |
---|---|
Description: | Data frame class for storing collective movement data (e.g. fish schools, ungulate herds, baboon troops) collected from GPS trackers or computer vision tracking software. |
Authors: | Simon Garnier [aut, cre] |
Maintainer: | Simon Garnier <[email protected]> |
License: | GPL-3 |
Version: | 0.3.2 |
Built: | 2024-10-16 03:47:45 UTC |
Source: | https://github.com/swarm-lab/trackdf |
This is an internal utility function to compute the mode(s) of a discrete distribution.
.Mode(x, na.rm = TRUE)
.Mode(x, na.rm = TRUE)
x |
A vector or matrix of discrete values. |
na.rm |
A logical value indicating whether NA values should be stripped before the computation proceeds (default: TRUE). |
A vector of values corresponding to the mode(s) of x.
Simon Garnier, [email protected]
Copy class and attributes from the original version of an object to a modified version.
.reclass(x, result)
.reclass(x, result)
x |
The original object, which has a class/attributes to copy |
result |
The modified object, which is/might be missing the class/attributes. |
result
, now with class/attributes restored.
Simon Garnier, [email protected]
Accessing columns, rows, or cells via $, [[, or [ is mostly
similar to regular data frames
.
However, the behavior is sometimes different for track tables based on
tibble
and data.table
. For
more info, refer to tibble's and
data.table
's subsetting documentation.
## S3 method for class 'track' x[...] ## S3 replacement method for class 'track' x[...] <- value
## S3 method for class 'track' x[...] ## S3 replacement method for class 'track' x[...] <- value
x |
A track table. |
... |
Other parameters to be passed to the extracting/subsetting
functions of |
value |
A suitable replacement value: it will be repeated a whole number
of times if necessary and it may be coerced: see the 'Coercion' section in
|
A subset of the track table is [
is called, or a modified version
of the track table if [<-
is called.
Simon Garnier, [email protected]
data(short_tracks) short_tracks[1] short_tracks[1, ] short_tracks[1, 1] short_tracks$id[short_tracks$id == "1"] <- "0" short_tracks[short_tracks[, 1] == "0", 1] <- "1"
data(short_tracks) short_tracks[1] short_tracks[1, ] short_tracks[1, 1] short_tracks$id[short_tracks$id == "1"] <- "0" short_tracks[short_tracks[, 1] == "0", 1] <- "1"
bind_tracks uses data.table::rbindlist
to combine track tables by rows, but makes sure that you cannot bind
together two tables with different projections or time zones, that the
projection attribute is inherited by the resulting track table, and that
track tables based on different table classes are coerced to the same table
class.
bind_tracks(...)
bind_tracks(...)
... |
A list containing track table objects, or the names of track table objects separated by commas. The track tables must have the same projection and time zone. |
A track table.
Simon Garnier, [email protected]
data(short_tracks) bind_tracks(short_tracks, short_tracks) bind_tracks(list(short_tracks, short_tracks))
data(short_tracks) bind_tracks(short_tracks, short_tracks) bind_tracks(list(short_tracks, short_tracks))
The following methods will convert track tables to and from other common formats used for processing tracking and spatial data.
as_track(x, table = "df", ...) ## S3 method for class 'MoveStack' as_track(x, table = "df", ...) ## S3 method for class 'Move' as_track(x, table = "df", ...) as_move(x, ...) ## S3 method for class 'track' as_move(x, ...) ## S3 method for class 'SpatialPointsDataFrame' as_track(x, table = "df", ...) as_sp(x, ...) ## S3 method for class 'track' as_sp(x, ...) ## S3 method for class 'ltraj' as_track(x, table = "df", ...) as_ltraj(x, ...) ## S3 method for class 'track' as_ltraj(x, ...) ## S3 method for class 'telemetry' as_track(x, table = "df", ...) ## S3 method for class 'list' as_track(x, table = "df", ...) as_telemetry(x, ...) ## S3 method for class 'track' as_telemetry(x, ...) ## S3 method for class 'moveData' as_track(x, table = "df", type = c("LL", "UTM"), ...) as_moveHMM(x, ...) ## S3 method for class 'track' as_moveHMM(x, ...)
as_track(x, table = "df", ...) ## S3 method for class 'MoveStack' as_track(x, table = "df", ...) ## S3 method for class 'Move' as_track(x, table = "df", ...) as_move(x, ...) ## S3 method for class 'track' as_move(x, ...) ## S3 method for class 'SpatialPointsDataFrame' as_track(x, table = "df", ...) as_sp(x, ...) ## S3 method for class 'track' as_sp(x, ...) ## S3 method for class 'ltraj' as_track(x, table = "df", ...) as_ltraj(x, ...) ## S3 method for class 'track' as_ltraj(x, ...) ## S3 method for class 'telemetry' as_track(x, table = "df", ...) ## S3 method for class 'list' as_track(x, table = "df", ...) as_telemetry(x, ...) ## S3 method for class 'track' as_telemetry(x, ...) ## S3 method for class 'moveData' as_track(x, table = "df", type = c("LL", "UTM"), ...) as_moveHMM(x, ...) ## S3 method for class 'track' as_moveHMM(x, ...)
x |
An object to convert. |
table |
A string indicating the class of the table on which the track
table should be built. It can be a |
... |
Other parameters to be passed to:
|
type |
For converting |
The coordinates converted in the chosen format.
Simon Garnier, [email protected]
## Not run: data(short_tracks) if (requireNamespace("moveVis", quietly = TRUE)) { mv <- as_move(short_tracks) as_track(mv) } if (requireNamespace("sp", quietly = TRUE)) { sp <- as_sp(short_tracks) as_track(sp) } if (requireNamespace("adehabitatLT", quietly = TRUE)) { lt <- as_ltraj(short_tracks) as_track(lt) } if (requireNamespace("ctmm", quietly = TRUE)) { tl <- as_telemetry(short_tracks) as_track(tl) } if (requireNamespace("moveHMM", quietly = TRUE)) { hhm <- as_moveHMM(short_tracks, type = "LL") as_track(hhm) } ## End(Not run)
## Not run: data(short_tracks) if (requireNamespace("moveVis", quietly = TRUE)) { mv <- as_move(short_tracks) as_track(mv) } if (requireNamespace("sp", quietly = TRUE)) { sp <- as_sp(short_tracks) as_track(sp) } if (requireNamespace("adehabitatLT", quietly = TRUE)) { lt <- as_ltraj(short_tracks) as_track(lt) } if (requireNamespace("ctmm", quietly = TRUE)) { tl <- as_telemetry(short_tracks) as_track(tl) } if (requireNamespace("moveHMM", quietly = TRUE)) { hhm <- as_moveHMM(short_tracks, type = "LL") as_track(hhm) } ## End(Not run)
dplyr
methods for track tables objects.
## S3 method for class 'track' select(.data, ...) ## S3 method for class 'track' rename(.data, ...) ## S3 method for class 'track' filter(.data, ...) ## S3 method for class 'track' arrange(.data, ...) ## S3 method for class 'track' mutate(.data, ...) ## S3 method for class 'track' transmute(.data, ...) ## S3 method for class 'track' summarise(.data, ...) ## S3 method for class 'track' summarize(.data, ...) ## S3 method for class 'track' group_by(.data, ...) ## S3 method for class 'track' ungroup(x, ...) ## S3 method for class 'track' slice_sample(.data, ...) ## S3 method for class 'track' do(.data, ...) ## S3 method for class 'track' slice(.data, ...) ## S3 method for class 'track' semi_join(x, ...) ## S3 method for class 'track' anti_join(x, ...) ## S3 method for class 'track' inner_join(x, ...) ## S3 method for class 'track' left_join(x, ...) ## S3 method for class 'track' right_join(x, ...) ## S3 method for class 'track' full_join(x, ...) ## S3 method for class 'track' nest_join(x, ...) ## S3 method for class 'track' distinct(.data, ...) ## S3 method for class 'track' rowwise(data, ...)
## S3 method for class 'track' select(.data, ...) ## S3 method for class 'track' rename(.data, ...) ## S3 method for class 'track' filter(.data, ...) ## S3 method for class 'track' arrange(.data, ...) ## S3 method for class 'track' mutate(.data, ...) ## S3 method for class 'track' transmute(.data, ...) ## S3 method for class 'track' summarise(.data, ...) ## S3 method for class 'track' summarize(.data, ...) ## S3 method for class 'track' group_by(.data, ...) ## S3 method for class 'track' ungroup(x, ...) ## S3 method for class 'track' slice_sample(.data, ...) ## S3 method for class 'track' do(.data, ...) ## S3 method for class 'track' slice(.data, ...) ## S3 method for class 'track' semi_join(x, ...) ## S3 method for class 'track' anti_join(x, ...) ## S3 method for class 'track' inner_join(x, ...) ## S3 method for class 'track' left_join(x, ...) ## S3 method for class 'track' right_join(x, ...) ## S3 method for class 'track' full_join(x, ...) ## S3 method for class 'track' nest_join(x, ...) ## S3 method for class 'track' distinct(.data, ...) ## S3 method for class 'track' rowwise(data, ...)
... |
Additional arguments to be passed to the corresponding
|
data , .data , x
|
A track table. |
This function attempts to automatically detect duplicated
data in track
tables.
duplicated_data(x, type = "txy")
duplicated_data(x, type = "txy")
x |
|
type |
A character string or a vector of character strings indicating
the type of duplications to look for. The strings can be any combination
of |
A track table of all observations that are duplicated, as per the
duplication rule defined by type
.
Incomplete data (that is, data containing "NAs") are ignored.
Simon Garnier, [email protected]
# Create data set with duplicated data data(short_tracks) t_df <- track(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek", table = "df") t_df <- bind_tracks(t_df, t_df[1:10, ], t_df[100:110, ]) # Find duplicated timestamps duplicated <- duplicated_data(t_df)
# Create data set with duplicated data data(short_tracks) t_df <- track(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek", table = "df") t_df <- bind_tracks(t_df, t_df[1:10, ], t_df[100:110, ]) # Find duplicated timestamps duplicated <- duplicated_data(t_df)
This is a re-export of the filter
function
in the dplyr
package. See the help
.data |
See |
... |
Other args |
This function attempts to automatically detect inconsistent
locations (for instance due to a writing error or GPS inaccuracies) in
track
tables.
inconsistent_data(x, s = 15)
inconsistent_data(x, s = 15)
x |
|
s |
The discrimination threshold for the outlier detection algorithm. Higher values correspond to less outliers. |
A track table of all inconsistent data.
Simon Garnier, [email protected]
# Create data set with inconsistent data data(tracks) t_df <- track(x = tracks$x, y = tracks$y, t = tracks$t, id = tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek", table = "df") t_df$x[1000] <- t_df$x[1000] * 1.0001 t_df$y[4000] <- t_df$y[4000] * 1.00001 # Find inconsistent data inconsistent <- inconsistent_data(t_df)
# Create data set with inconsistent data data(tracks) t_df <- track(x = tracks$x, y = tracks$y, t = tracks$t, id = tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek", table = "df") t_df$x[1000] <- t_df$x[1000] * 1.0001 t_df$y[4000] <- t_df$y[4000] * 1.00001 # Find inconsistent data inconsistent <- inconsistent_data(t_df)
Track tables produced by track_df
can use a
cartesian (x, y, z) or a geographic (latitude, longitude, altitude)
coordinate system. This function helps determine which is being used in a
particular table.
is_geo(x)
is_geo(x)
x |
A track data table as produced by |
A logical.
Simon Garnier, [email protected]
data(short_tracks) is_geo(short_tracks)
data(short_tracks) is_geo(short_tracks)
Test whether a variable contains a track table as produced
by track_df
, track_tbl
, or track_dt
.
is_track(x)
is_track(x)
x |
An object to test. |
A logical indicating whether the variable contains a track table
(TRUE
) or not (FALSE
).
Simon Garnier, [email protected]
data(short_tracks) is_track(short_tracks)
data(short_tracks) is_track(short_tracks)
This function attempts to automatically detect missing data (for
instance due to writing errors) in track
tables.
missing_data(x, begin = NULL, end = NULL, step = NULL)
missing_data(x, begin = NULL, end = NULL, step = NULL)
x |
|
begin |
A full time stamp (date+time) in |
end |
A full time stamp (date+time) in |
step |
A |
A track table of all observations with missing data. The missing data
is indicated with NA
.
Simon Garnier, [email protected]
# Create data set with missing time stamps data(short_tracks) t_df <- track(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek", table = "df") t_df <- t_df[-c(10, 100), ] # Find missing data missing <- missing_data(t_df)
# Create data set with missing time stamps data(short_tracks) t_df <- track(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek", table = "df") t_df <- t_df[-c(10, 100), ] # Find missing data missing <- missing_data(t_df)
Track tables produced by track_df
can have 2 (x,y)
or 3 (x, y, z) spatial dimensions. This function returns the number of
spatial dimensions of a track table.
n_dims(x)
n_dims(x)
x |
A track data table as produced by |
A numeric value.
Simon Garnier, [email protected]
data(short_tracks) n_dims(short_tracks)
data(short_tracks) n_dims(short_tracks)
Track tables produced by track_df
can contain
multiple tracks (e.g., from different animals). This function returns the
number of tracks in a track table.
n_tracks(x)
n_tracks(x)
x |
A track data table as produced by |
A numeric value.
Simon Garnier, [email protected]
data(short_tracks) n_tracks(short_tracks)
data(short_tracks) n_tracks(short_tracks)
Functions to access or modify the projection of a data table. Changing the projection will trigger automatically the conversion of the locations in the new coordinate system.
projection(x) projection(x) <- value project(x, value)
projection(x) projection(x) <- value project(x, value)
x |
A track table. |
value |
A character string or a |
A track table.
It is not possible to modify the projection if missing coordinates are present.
Simon Garnier, [email protected]
data(short_tracks) projection(short_tracks) tracks_projected <- project(short_tracks, "+proj=somerc") projection(tracks_projected) projection(tracks_projected) <- "+proj=longlat" projection(tracks_projected)
data(short_tracks) projection(short_tracks) tracks_projected <- project(short_tracks, "+proj=somerc") projection(tracks_projected) projection(tracks_projected) <- "+proj=longlat" projection(tracks_projected)
A dataset containing the trajectories of two goats through the Namibian desert.
short_tracks
short_tracks
A track table with 18 rows and 4 variables:
Identity of the goat
Time of the observation
Longitude
Latitude
track
constructs track tables based on data.frame
(the default), tibble
, or data.table
.
track
is a convenience function that executes track_df
,
track_tbl
, or track_dt
based on the value of the 'table'
parameter. Track tables can be used like the data structure they are build
upon but with a notable difference: they have an extra attribute to store
the projection of the track coordinates, and modifying the projection will
automatically trigger the appropriate conversion of the coordinates.
track(x, y, z, t, id, ..., proj, origin, period, tz, format, table = "df") track_df(x, y, z, t, id, ..., proj, origin, period, tz, format) track_tbl(x, y, z, t, id, ..., proj, origin, period, tz, format) track_dt(x, y, z, t, id, ..., proj, origin, period, tz, format)
track(x, y, z, t, id, ..., proj, origin, period, tz, format, table = "df") track_df(x, y, z, t, id, ..., proj, origin, period, tz, format) track_tbl(x, y, z, t, id, ..., proj, origin, period, tz, format) track_dt(x, y, z, t, id, ..., proj, origin, period, tz, format)
x , y , z
|
Numeric vectors representing the coordinates of the locations.
|
t |
A numeric vector or a vector of objects that can be coerced to
date-time objects by |
id |
A vector that can be coerced to a character vector by
|
... |
A set of name-value pairs. Arguments are evaluated sequentially,
so you can refer to previously created elements. These arguments are
processed with |
proj |
A character string or a |
origin |
Something that can be coerced to a date-time object by
|
period |
A character vector in a shorthand format (e.g. "1 second") or
ISO 8601 specification. This is used when |
tz |
A time zone name. See |
format |
A character string indicating the formatting of 't'. See
When supplied parsing is performed by strptime(). For this reason consider using specialized parsing functions in lubridate. |
table |
A string indicating the class of the table on which the track
table should be built. It can be a |
A track table, which is a colloquial term for an object of class
track
.
Simon Garnier, [email protected]
data(short_tracks) t_df <- track(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek", table = "df") t_df <- track_df(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek") t_tbl <- track_tbl(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek") t_dt <- track_dt(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek")
data(short_tracks) t_df <- track(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek", table = "df") t_df <- track_df(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek") t_tbl <- track_tbl(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek") t_dt <- track_dt(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t, id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek")
A dataset containing the trajectories of two goats through the Namibian desert.
tracks
tracks
A track table with 7194 rows and 4 variables:
Identity of the goat
Time of the observation
Longitude
Latitude