I don't think this is the best way to go about your problem, I used that code just for creating sample data to use with my reproducible example, please read the guide on the link I gave you so you can understand this concept and try to better explain your problem.