Iteration issue with dynamic tibble

47 Views Asked by At

I am using a tibble: 20 x 1 for iteration extracted from my df. The problem occurs when I use tibble data as a filter.

# Selecting unique list of 20 numeric variables from my data
    Lotes <- unique(dados[,1]) 

# Find its length as Integer for iteration
    LotesMatrix <- length(as.matrix(Lotes)) ##20L
    
# iteration with my df named 'dados'
    for (i in 1:LotesMatrix) {
      Lote <- Lotes[i,1]
      dados1 <- dados[dados$Lote == Lote,]
      print(header(dados1))
    }

First iteration occurs fine, but second onwards returns my headers:

# ... with 30,048 more rows, and 10 more variables: `TRY-5` <dbl>, `TRY-6` <dbl>, `TRY-7` <dbl>,
#   `TRY-8` <dbl>, `TRY-9` <dbl>, `Total (1-9)` <dbl>, Adicionais <dbl>, Equivalente <dbl>,
#   Total <dbl>, Data <dttm>
# A tibble: 0 x 22 
1

There are 1 best solutions below

0
On

The answer was to set the dynamic variable searched into string. i.e.

Lote <- as.integer(Lotes[i,1])