Skip to contents

Format time series data frame into a matrix

Usage

ts2mat(
  ts,
  sensor = "time series",
  twl_offset = 0,
  value = "value",
  twl_time_tolerance = 180
)

Arguments

ts

data.frame of a tag, containing at least date and value.

sensor

sensor name used in messages.

twl_offset

Shift of the middle of the night compared to 00:00 UTC (in hours). If not provided, it uses the middle of all nights.

value

column name to extract

twl_time_tolerance

Maximum allowed time difference in seconds between observations and the regular grid. Observations beyond this threshold will be set to NA. Default is 180 seconds (3 minutes). Half the sampling interval is always allowed, so that drift-corrected timestamps sliding against the grid are kept.

Value

A list with value and date matrices (time of day × day), the temporal resolution res (in seconds), the day of each column and the time of each row.

Examples

withr::with_dir(system.file("extdata", package = "GeoPressureR"), {
  tag <- tag_create("18LX", quiet = TRUE)
})

mat <- ts2mat(tag$pressure)
str(mat)
#> List of 5
#>  $ value: num [1:48, 1:14] 989 989 990 990 989 989 990 990 991 990 ...
#>  $ date : num [1:48, 1:14] 1.5e+09 1.5e+09 1.5e+09 1.5e+09 1.5e+09 ...
#>  $ res  : num 1800
#>  $ day  : Date[1:14], format: "2017-07-27" "2017-07-28" ...
#>  $ time : chr [1:48] "00:00" "00:30" "01:00" "01:30" ...