0

I'm facing some trouble with this R looping. I imagine it's because R isn't so prepared to code this kind of looping.

Thank you in advance!

df <- data.frame("x1" = NULL)

a <- 1
j <- 1

while (a<201)
{
  for(i in 1:1156)
  {
    df[j,"x1"] <- j
    j <- j + 1
  }
  a <- a + 1
}

length(df$pontos)
df
Cettt
  • 10,939
  • 7
  • 31
  • 53
Felipe Dourado
  • 369
  • 1
  • 9

2 Answers2

2

There are no errors in the codes actually. If you put print(a) after a <- a + 1, you can see that the codes work but extremely slow. I think that is the reason why you thought the loop never ends.

Utaha Tahiro
  • 95
  • 10
0

It runs for me if you decrease the iterations in the inner for loop to 100. It might just be taking a while. Could the outer loop just be a for loop as well?