Indice inside a nested for loop

Hello, I wanted to save all the links created in this nested loop but IDK how to index them

for(i in 1:length(ano)){

for(j in 1:length(bimestre))    {
    
       x[i] <-  paste(base_url_rreo,
                              "an_exercicio=", ano[i], "&",
                              "nr_periodo=", bimestre[j], "&",
                              "co_tipo_demonstrativo=", tipo_relatorio, "&",
                              "no_anexo=", num_anexo, "&",
                              "id_ente=", ente, sep = "")


   
}

}

You could do it like this.

x <- vector("character", length(ano)*length(bimestre))
k <- 0
for (i in 1:length(ano)){
  for(j in 1:length(bimestre)){
       k <- k + 1
       x[k] <-  paste(base_url_rreo,
                              "an_exercicio=", ano[i], "&",
                              "nr_periodo=", bimestre[j], "&",
                              "co_tipo_demonstrativo=", tipo_relatorio, "&",
                              "no_anexo=", num_anexo, "&",
                              "id_ente=", ente, sep = "")
  }
}
1 Like

It worked fine! tks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.