Do loop help in R studio

See the FAQ: How to do a minimal reproducible example reprex for beginners to provide two example datasets to illustrate the problem.