find_breaks: Find changes for integer variable

Description Usage Arguments Value Examples

View source: R/segmentation_helper_functions.R

Description

Identify changes within a discrete variable. These values can be used to pre-specify breakpoints within the segmentation model using segment_behavior.

Usage

1
find_breaks(dat, ind)

Arguments

dat

A data frame containing the data for each animal ID.

ind

character. The name of the column storing the discrete variable of interest.

Value

A vector of breakpoints is returned based on the data provided. If wishing to identify separate breakpoints per animal ID, this function should be mapped onto a list generated by df_to_list.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#simuluate data
var<- sample(1:3, size = 50, replace = TRUE)
var<- rep(var, each = 20)
id<- rep(1:10, each = 100)

#create data frame
dat<- data.frame(id, var)

#create list
dat.list<- df_to_list(dat = dat, ind = "id")

#run function using purrr::map()
breaks<- purrr::map(dat.list, ~find_breaks(dat = ., ind = "var"))

#or with lapply()
breaks1<- lapply(dat.list, find_breaks, ind = "var")

bayesmove documentation built on Oct. 22, 2021, 9:08 a.m.