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$

closed as too broad by Peter, georg-un, Mark.F, Dan Scally, Stephen Rauch Aug 14 at 12:44

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\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.