Title: | Count of Sequential Events |
Version: | 0.1.1 |
Description: | Count the occurrence of sequences of values in a vector that meets certain conditions of length and magnitude. The method is based on the Run Length Encoding algorithm, available with base R, inspired by A. H. Robinson and C. Cherry (1967) <doi:10.1109/PROC.1967.5493>. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.1 |
Imports: | checkmate |
Suggests: | testthat (≥ 3.0.0), ggplot2, dplyr |
Config/testthat/edition: | 3 |
Config/Needs/website: | rmarkdown |
URL: | https://rfsaldanha.github.io/nseq/ |
BugReports: | https://github.com/rfsaldanha/nseq/issues |
NeedsCompilation: | no |
Packaged: | 2024-05-30 08:42:58 UTC; raphael |
Author: | Raphael Saldanha |
Maintainer: | Raphael Saldanha <raphael.de-freitas-saldanha@inria.fr> |
Repository: | CRAN |
Date/Publication: | 2024-05-31 14:00:02 UTC |
Shifts vector values to right or left
Description
Shifts vector values to right or left
Usage
shift(x, n, invert = FALSE, default = NA)
Arguments
x |
Vector for which to shift values |
n |
Number of places to be shifted. Positive numbers will shift to the right by default. Negative numbers will shift to the left by default. The direction can be inverted by the invert parameter. |
invert |
Whether or not the default shift directions should be inverted. |
default |
The value that should be inserted by default. |
Value
a vector.
Examples
# Lag
shift(c(2,3,5,6,7), n = 1, default = 0)
# Lead
shift(c(2,3,5,6,7), n = -1, default = 0)
Run Length Encoding and return result as a data frame
Description
Given a tibble object and a variable y
, this function will count the number of occurrence of each element in y
in the sequence that they appear, and return this count as a tibble object.
Usage
trle(x)
Arguments
x |
a vector. |
Value
a data.frame
object.
See Also
Examples
trle(c(8,15,20,0,0,0,0,5,9,12))
Count the number of events in a sequence
Description
This function will count the occurrence of sequential events that meets some conditions.
Usage
trle_cond(x, a_op = "gte", a, b_op = "gte", b, isolated = FALSE)
Arguments
x |
numeric vector. |
a_op , b_op |
character. Operator, |
a |
integer. Length of period threshold. |
b |
integer. Value threshold. |
isolated |
logical. Consider only isolated events, i.e. surrounded by zeros. On this case, |
Details
Example: In a vector, how many sequences have at least 3 consecutive observations (a_op = "gte", a = 3
) with values equal or greater than 5 (b_op = "gte", b = 5
)?
Value
a numeric value.
Examples
# How many sequences have at least 3 consecutive observations with value equal or greater than 5?
trle_cond(x = c(8,15,20,0,0,0,0,5,9,12), a_op = "gte", a = 3, b_op = "gte", b = 5)
Statistics of events in a sequence
Description
This function will compute statistics of sequential events that meets some conditions.
Usage
trle_cond_stat(x, b, b_op, stat)
Arguments
x |
numeric vector. |
b |
integer. Value threshold. |
b_op |
character. Operator, |
stat |
character. A statistic to be calculated. One of: max, min, mean, median, sd, var. |
Details
Example: in a vector, what is the maximum size of sequences with values equal or greater than 5?
Value
a numeric value
Examples
# What is the maximum size of sequences with values equal or greater than 5?
trle_cond_stat(c(4,6,6,4,7,8,9), b = 5, b_op = "gte", stat = "max")