behavr (version 0.3.1)

stitch_on: Stitch behavioural data by putting together the same individuals recorded over different experiments on the basis of a user-defined identifier

Description

This function can merge rows of data from the same individual that was recorded over multiple experiments. A usual scenario in which stitch_on can be used is when an experiment is interrupted and a new recording is started on the same biological subjects. Stitching assumes the users has defined a unique id in the metadata that refers to a specific individual. Then, if any data that comes from the same unique id, it is merged.

Usage

stitch_on(x, on, time_ref = "datetime", use_time = F, time_variable = "t")

Arguments

x

behavr object

on

name of a metavariable serving as a unique id (per individual)

time_ref

name of a metavariable used to align time (e.g. "date", or "datetime")

use_time

whether to use time as well as date

time_variable

name of the variable describing time

Value

a behavr table

Details

When several rows of the metadata match a unique id (several experiments), the first (in time) experiment is used as the reference id. The data from the following one(s) will be added with a time lag equals to the difference between the values of time_ref. When data is not aligned to circadian time, it makes sense to set use_time = TRUE. Otherwise, the assumption is that the time is already aligned to a circadian reference, so only the date is used.

See Also

  • behavr -- to formally create a behavr object

Examples

Run this code
# NOT RUN {
set.seed(1)
met1 <- data.table::data.table(uid = 1:5,id = 1:5,
                               condition = letters[1:5],
                               sex = c("M", "M", "M", "F", "F"),
                               key = "id")
met2 <- data.table::data.table(uid = 1:4, id = 6:9,
                               condition = letters[1:4],
                               sex=c("M", "M", "M", "F"),
                               key = "id")
met1[, datetime := as.POSIXct("2015-01-02")]
met2[, datetime := as.POSIXct("2015-01-03")]
met <- rbind(met1, met2)
data.table::setkeyv(met, "id")
t <- 1L:100L
data <- met[,list(t = t,
                  x = rnorm(100),
                  y = rnorm(100),
                  eating = runif(100) > .5 ),
            by = "id"]
d <- behavr(data, met)
summary(d)
d2 <- stitch_on(d, on = "uid")
summary(d2)

# }

Run the code above in your browser using DataCamp Workspace