<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Hi, have a look at `?melt` and the reshaping vignette: <a href="https://github.com/Rdatatable/data.table/wiki/Getting-started">https://github.com/Rdatatable/data.table/wiki/Getting-started</a></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div> <br> <div id="bloop_sign_1447011806252148992" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Arun</div></div> <br><p class="airmail_on">On 8 November 2015 at 20:42:05, Stefano Grioni (<a href="mailto:sgrioni@chicagobooth.edu">sgrioni@chicagobooth.edu</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>
<title></title>
<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>
_______________________________________________
<br>datatable-help mailing list
<br>datatable-help@lists.r-forge.r-project.org
<br>https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</div></div></span></blockquote></body></html>