<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><p>Hi Frank,</p>
<p>The <code>data.frame</code> way of referring to column names or numbers requires <code>with=FALSE</code>. This is because the default data.table-like operations are more common where <code>with=TRUE</code>. Also, <code>data.tables</code> are designed with <em>really</em> huge data sets in mind and avoiding as many copies as possible. So, unless there’s a strong reason, the <code>data.table</code> philosophy would be to avoid copies (ex: <code>DT[, 1, with=FALSE]</code> will create a copy).</p>
<p>That being said, another alternative is to subset the <code>data.table</code> way (where <code>with=TRUE</code> by default):</p>
<pre><code>DT2 = DT[, list(A,D,B)] # list(1,4,2) won't work. Read FAQ 1.1-1.5
setnames(DT2, c("a", "d", "B"))
</code></pre>
<p>It’s also generally considered a bad practice to subset columns by using column numbers - prone to errors.</p>
<p>Hope this helps.</p>
<p><style>body{font-family:Helvetica,Arial;font-size:13px}</style><style>body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
padding:1em;
margin:auto;
background:#fefefe;
}
h1, h2, h3, h4, h5, h6 {
font-weight: bold;
}
h1 {
color: #000000;
font-size: 28pt;
}
h2 {
border-bottom: 1px solid #CCCCCC;
color: #000000;
font-size: 24px;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
color: #777777;
background-color: inherit;
font-size: 14px;
}
hr {
height: 0.2em;
border: 0;
color: #CCCCCC;
background-color: #CCCCCC;
}
p, blockquote, ul, ol, dl, li, table, pre {
margin: 15px 0;
}
a, a:visited {
color: #4183C4;
background-color: inherit;
text-decoration: none;
}
#message {
border-radius: 6px;
border: 1px solid #ccc;
display:block;
width:100%;
height:60px;
margin:6px 0px;
}
button, #ws {
font-size: 12 pt;
padding: 4px 6px;
border-radius: 5px;
border: 1px solid #bbb;
background-color: #eee;
}
code, pre, #ws, #message {
font-family: Monaco;
font-size: 10pt;
border-radius: 3px;
background-color: #F8F8F8;
color: inherit;
}
code {
border: 1px solid #EAEAEA;
margin: 0 2px;
padding: 0 5px;
}
pre {
border: 1px solid #CCCCCC;
overflow: auto;
padding: 4px 8px;
}
pre > code {
border: 0;
margin: 0;
padding: 0;
}
#ws { background-color: #f8f8f8; }
table {
border-collapse: collapse;
font-family: Helvetica, arial, freesans, clean, sans-serif;
color: rgb(51, 51, 51);
font-size: 15px; line-height: 25px;
padding: 0; }
table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0; }
table tr:nth-child(2n) {
background-color: #f8f8f8; }
table tr th {
font-weight: bold;
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
table tr td {
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
table tr th :first-child, table tr td :first-child {
margin-top: 0; }
table tr th :last-child, table tr td :last-child {
margin-bottom: 0; }
.send { color:#77bb77; }
.server { color:#7799bb; }
.error { color:#AA0000; }</style></p><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> <div id="bloop_sign_1405954185587527936" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">Arun</div></div> <div style="color:black"><br>From: <span style="color:black">Frank S.</span> <a href="mailto:f_j_rod@hotmail.com">f_j_rod@hotmail.com</a><br>Reply: <span style="color:black">Frank S.</span> <a href="mailto:f_j_rod@hotmail.com">f_j_rod@hotmail.com</a><br>Date: <span style="color:black">July 21, 2014 at 4:48:54 PM</span><br>To: <span style="color:black">Chris Neff</span> <a href="mailto:caneff@gmail.com">caneff@gmail.com</a>, <span style="color:black">datatable-help@lists.r-forge.r-project.org</span> <a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>Subject: <span style="color:black"> Re: [datatable-help] Construct a new data table from another <br></span></div><br> <blockquote type="cite" class="clean_bq"><span><div class="hmmessage"><div></div><div>
<title></title>
<div dir="ltr">
<p abp="100">Thanks Chris,</p>
<p abp="100"> </p>
<p abp="100">But, is there any option in order to avoid writing
"with=FALSE" every time</p>
<p abp="100">in the next situation?:</p>
<p abp="100"> </p>
<p abp="100"> </p>
<p abp="100"># USING DATA FRAME <br abp="127">
set.seed(100)<br abp="128">
DF =
data.frame(A=letters[1:5],B=rnorm(5),C=rexp(5),D=runif(5))<br abp="129">
DF2 <- data.frame(a=DF[,1],d=DF[,4],B=DF[,2])<br abp="130">
<br abp="131">
If I do the equivalent operations under data table format, I'm onñy
able to obtain<br abp="132">
the same result with the following code:<br abp="133">
<br abp="134">
# USING DATA TABLE<br abp="135">
set.seed(100)<br abp="136">
DT =
data.table(A=letters[1:5],B=rnorm(5),C=rexp(5),D=runif(5))<br abp="137">
DT2 <- data.table(DT[,1,with=FALSE], DT[,4,with=FALSE],
DT[,2,with=FALSE])</p>
<p abp="100">setnames(DT2, c('a','d','B'))<br abp="138"></p>
<p abp="100"> </p>
<p abp="100">Thank you!</p>
</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><p></p></body></html>