x<-'1 2 3 4 5 6 7 apply(dados, 8
1 10 5 0 0 25 12, \(x) 0{
2 0 0 0 0 0 0 r <- 1rle(x)
3 40sum(r$lengths[r$values == 250] > 5 0 1 0 32)
4 0 10 6 3 0 0 2})
5 2 #> [1] 0 1 0 0 3 0 0
6 10 3 15 30 3 0 01
7 0 0 0 0
Created on 2022-08-18 by the reprex package (v2.0.1)
Para obter as sequências de valores menores que ou iguais a 1 é um bocado mais complicado. Mas também pode ser resolvido com um ciclo apply
, basta primeiro substituir os 1 por 0 e repetir o código acima.
apply(dados2, 01, \(x) {
0 x[x <= 18'
dados1] <- read.table(textConnection(x), header = TRUE, check.names0
= FALSE)
r <- apply(dados, 1, rle)
sapply(r, \(x)
sum(x$lengths[x$valuesr$lengths[r$values == 0] > 5)
})
#> [1] 0 1 0 0 01 0 1
Created on 2022-0810-18 by the19 with reprex packagev2.0.2 (v2.0.1)
Dados em formato dput
dados <x<-'1 2 3 4 5 6 7 8
1 structure(list( 10 5 0 0 25 12 0
2 0 `1` = 0 0 0 0 0 1:7,
3 40 25 5 0 1 0 32
4 0 `2` = c(10L,10 0L, 40L,6 0L, 2L, 10L,3 0L), 0 0 2
5 2 `3` = c(5L,0 0L, 25L, 10L,0 0L, 3L, 0L),0 3 0 0
6 10 `4` =3 c(0L, 0L, 5L,15 6L, 0L,30 15L, 0L),3 0 0
7 0 `5` = c0 0 0 0 0 18'
dados <- read.table(0LtextConnection(x), 0L,header 0L,= 3LTRUE, 0L,check.names 30L,= 0LFALSE),
y<-'1 2 3 4 5 6 7 8
1 10 `6` =5 c(25L, 0L, 1L,0 0L, 3L, 3L,0 0L), 25 12 0
2 0 `7` = c(12L,0 0L, 0L, 0L,0 0L, 0L, 0L),0 0 0 1
3 40 `8` =25 c(0L, 1L,5 32L, 2L, 0L,0 0L, 18L)), 1 0 32
4 0 class = "data10 6 3 0 0 2
5 2 0 0 0 1 0 0
6 10 3 15 30 3 0 0
7 0 0 0 0 0 0 18'
dados2 <- read.frame"table(textConnection(y), row.namesheader = c(NATRUE, -7L)check.names = FALSE)