Learn R Programming

arctools (version 1.1.6)

midnight_to_midnight: Expand activity data vector into midnight-to-midnight format

Description

Expand activity data vector such that its length is a multiple of number of minutes in a full day (1440).

Usage

midnight_to_midnight(acc, acc_ts)

Value

A numeric vector. A minute-level activity counts data vector in midnight-to-midnight format.

Arguments

acc

A numeric vector. A minute-level activity counts data vector.

acc_ts

A POSIXct vector. Time of activity data collection, corresponding to acc. We strongly recommended to use lubridate::ymd_hms() function to create acc_ts (see Examples below).

Details

In the returned vector, 1st observation corresponds to minute of 00:00-00:01 on the first day of data collection, and last observation corresponds to minute of 23:59-00:00 on the last day of data collection. Entries corresponding to no data in original activity data vector are filled with NA.

Examples

Run this code
## Read exemplary data
fpath_i <- system.file("extdata", extdata_fnames[1], package = "arctools")
dat_i   <- as.data.frame(data.table::fread(fpath_i))
acc     <- dat_i$vectormagnitude
acc_ts  <- lubridate::ymd_hms(dat_i$timestamp)
## Get acc data vector in "midnight_to_midnight" format
acc <- midnight_to_midnight(acc, acc_ts)
## Observe we have an integer number of days
length(acc) / 1440

Run the code above in your browser using DataLab