There is nothing fundamentally wrong with using a for loop but this is rarely the best way of doing things in R, if you could ask this with a minimal REPRoducible EXample (reprex) illustrating your issue, very likely someone will come up with a better (or at least more idiomatic) solution.
If you've never heard of a reprex before, you might want to start by reading this FAQ: