consecutive_T: Count number of consecutive 'TRUE' logicals

Description Usage Arguments Examples

View source: R/consecutive_T.R

Description

Counts the number of consecutive TRUEs in a logical vector. Restarts count of consecutive TRUEs when FALSE is encountered. Vector can either be a logical or a condition that evaluates to a logical. See examples. Based on a note from Bill Dunlap to R-devel (http://tolstoy.newcastle.edu.au/R/e4/devel/08/04/1206.html)

Usage

1

Arguments

x

logical vectir or a conditional statement that evaluates to a logical vector

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
tf <- sample(c(TRUE, FALSE), 15, TRUE, prob = c(0.75, 0.25))
consecutive_T(tf)

x <- rnorm(15, mean = -0.5)
consecutive_T(x < 0)

## Not run: 
# Works in tidyverse pipe context
library(dplyr)
df <- tibble(x = rnorm(10, -0.25)) %>%
  mutate(cons_lt_zero = consecutive_T(x < 0))

## End(Not run)

adamdsmith/nrsmisc documentation built on Aug. 13, 2019, 2:14 p.m.