<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix"><br>
And more info here (see both answers) :<br>
<a class="moz-txt-link-freetext" href="http://stackoverflow.com/questions/10225098/understanding-exactly-when-a-data-table-is-a-reference-to-vs-a-copy-of-another">http://stackoverflow.com/questions/10225098/understanding-exactly-when-a-data-table-is-a-reference-to-vs-a-copy-of-another</a><br>
<br>
On 10/03/14 05:20, Michael Nelson wrote:<br>
</div>
<blockquote
cite="mid:6FB5193A6CDCDF499486A833B7AFBDCDB81A54D9@ex-mbx-pro-05"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<style type="text/css" id="owaParaStyle"></style>
<div style="direction: ltr;font-family: Tahoma;color:
#000000;font-size: 10pt;">This is well explained in the help
file for `copy` (and `setnames`)
<div><br>
</div>
<div>DT <- DT2 </div>
<div><br>
</div>
<div>does *not* create a copy, it creates two object names that
refer to the same object reference.</div>
<div><br>
</div>
<div>If you want force the creation of a copy, use `copy`</div>
<div><br>
</div>
<div>DT <- copy(DT2)</div>
<div><br>
</div>
<div>Then your example will work as expected.</div>
<div><br>
</div>
<div><br>
<div style="font-family: Times New Roman; color: #000000;
font-size: 16px">
<hr tabindex="-1">
<div id="divRpF47660" style="direction: ltr;"><font
color="#000000" face="Tahoma" size="2"><b>From:</b>
<a class="moz-txt-link-abbreviated" href="mailto:datatable-help-bounces@lists.r-forge.r-project.org">datatable-help-bounces@lists.r-forge.r-project.org</a>
[<a class="moz-txt-link-abbreviated" href="mailto:datatable-help-bounces@lists.r-forge.r-project.org">datatable-help-bounces@lists.r-forge.r-project.org</a>] on
behalf of Manabu Sakamoto [<a class="moz-txt-link-abbreviated" href="mailto:manabu.sakamoto@gmail.com">manabu.sakamoto@gmail.com</a>]<br>
<b>Sent:</b> Monday, 10 March 2014 4:00 PM<br>
<b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<b>Subject:</b> [datatable-help] setnames on copy
data.table also renames original data.table object<br>
</font><br>
</div>
<div>
<div dir="ltr">Dear list,
<div><br>
</div>
<div>I have a data.table object for instance DT:</div>
<div><br>
</div>
<div>x <- seq(1:100)</div>
<div>y <- x^2</div>
<div>DT <- data.table(X=x, Y=y)</div>
<div><br>
</div>
<div>and I produce a copy</div>
<div><br>
</div>
<div>DT2 <- DT</div>
<div><br>
</div>
<div>which I rename</div>
<div><br>
</div>
<div>setnames(DT2, c("A","B"))</div>
<div><br>
</div>
<div>this somehow also renames DT, the names of which
are now "A" and "B".</div>
<div><br>
</div>
<div>How can I just rename the copy and keep the names
of the original?</div>
<div><br>
</div>
<div>Many thanks,</div>
<div>Manabu<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">Manabu Sakamoto, PhD
<div><a moz-do-not-send="true"
href="mailto:manabu.sakamoto@gmail.com"
target="_blank">manabu.sakamoto@gmail.com</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
datatable-help mailing list
<a class="moz-txt-link-abbreviated" href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a>
<a class="moz-txt-link-freetext" href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a></pre>
</blockquote>
<br>
</body>
</html>