New to R. New to group. Using for loop on a horse racing database.

It seems you want to rotate your data from being in rows to being in columns. Is that correct?
It would be easiest to help you if we had an example of your data. Please run the command

dput(head(my_new_data))

and paste the output into a new post. On the line in the post just before and just after the output, place three back ticks, ```, so that the output is formatted as code.