<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>