-1

Good morning, I have to do a loop in R and some function inside this loop print each results in the console of R, there is a function to stop this printing? I let here an example of code:

for (i in 1:100){
d=datafr[,i]
a=gamlss(y~1, data=d)
summary(a)
}

in this easy code the GAMLSS function print in the console a lot of information.

Thanks!

Lorenzo
  • 21
  • 3
  • 1
    I'm not sure what you're trying to do. If you don't want to print to console just comment out (or remove) the line. Note that your `for` loop does not save anything. `d` and `a` get overwritten in every step. So in its current form it's a pretty pointless loop ;-) – Maurits Evers Jul 19 '22 at 11:06
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 19 '22 at 13:19

2 Answers2

0

Use the break statement to break out of the for loop. Put it in an if statement to break out when some condition is met. For example, if you want to break out of the loop after a certain number of iterations:

 if (i > desired_number) {
    break
    }
0

a=gamlss(y~1, data=d, trace=FALSE)

as on page 91 of "Stasinopoulos et al. (2019) Flexible Regression and Smoothing: Using GAMLSS in R"

Robert
  • 186
  • 2