0
$\begingroup$

I have an R function for (i in 1:10) that reads in data and performs some cleaning. Is it possible to write a flexible statement to execute certain parts of the code conditionally, for example have different steps for i = 2 and 8?

$\endgroup$
  • $\begingroup$ Hi, welcome to the forum. Your question is very vague. Please add more details in future questions and make sure you describe your problem in a good way. $\endgroup$ – Peter Aug 14 at 8:10
0
$\begingroup$

You can add conditions inside the loop if you want:

for (i in 1:10){
  if (i<=2){print("1-2")}
  if (i>2){print(" >2")}
}
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.