Transpose in dataframe with loops

I think you are looking for something like tidyr::pivot_longer()

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.