<div dir="ltr"><div>Hello,</div><div><br></div><div>I am new to R and trying to understand how data manipulation works. I have a CSV file which allows me to build a data table that looks like the following (simplified example):</div><div><br></div><div>>db</div><div>  Â names ages grade_spring_quarter grade_summer_quarter</div><div>1: Â John Â  24 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â A Â  Â  Â  Â  Â  Â  Â  Â  Â  A+</div><div>2: Steve Â  16 Â  Â  Â  Â  Â  Â  Â  Â  Â  B+ Â  Â  Â  Â  Â  Â  Â  Â  Â  Â B</div><div>3: Peter Â  12 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â C Â  Â  Â  Â  Â  Â  Â  Â  Â  B+</div><div><br></div><div>Now, my goal is to denormalize the data table in order to transform the last 2 columns in rows, therefore obtaining the following:</div><div><br></div><div>> db2</div><div>  Â names ages quarter grades</div><div>1: Â John Â  24 Â spring Â  Â  Â A</div><div>2: Steve Â  16 Â spring Â  Â  B+</div><div>3: Peter Â  12 Â spring Â  Â  Â C</div><div>4: Â John Â  24 Â summer Â  Â  A+</div><div>5: Steve Â  16 Â summer Â  Â  Â B</div><div>6: Peter Â  12 Â summer Â  Â  B+</div><div><br></div><div>I think that I would be able to do it using for loops, but I doubt that's the most efficient way. I have started looking into the Join functionality of data table but so far didn't manage to build db2 from db that way. </div><div><br></div><div>Do you see how I could proceed? </div><div><br></div><div>Many thanks</div><div><br>Stefano</div></div>