I would like to create new data frames within a list, where TRUE and FALSE logicals alternate and in a new column the number about how often they showed up consecutively in the original dataframes within lists.
library(dplyr)
set.seed(94756)
mat1 <- matrix(sample(seq(-1,100, 0.11),50, replace = TRUE),ncol = 5)
mat1 <- as_tibble(mat1)
mat2 <- matrix(sample(seq(-1,100, 0.11),50, replace = TRUE),ncol = 5)
mat2 <- as_tibble(mat2)
mat3 <- matrix(sample(seq(-1,100, 0.11), 50,replace = TRUE),ncol = 5)
mat3 <- as_tibble(mat3)
data <- list(mat1, mat2, mat3)
data1 <- purrr::map(data, ~tibble::add_column(., V1_logical = between(.$V2, 20, 60), .after = 'V1'))
r_pre <- lapply(data1, "[", 2)
That in the end I get an example like this:
$logical = TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE ...
$length = 2, 1, 3 (=marker), 2, 1, 3, 7...