<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;">Ben, </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;">That’s very clear.. Would you mind making a Pull Request with this change?</div> <br> <div id="bloop_sign_1424448631894757120" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Arun</div></div> <br><p style="color:#000;">On 19 Feb 2015 at 15:49:16, Ben Tupper (<a href="mailto:btupper@bigelow.org">btupper@bigelow.org</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div></div><div>
<title></title>
<font face="Monaco" style="font-size: 14px;">Hi,</font>
<div><br>
<div>
<div>On Feb 18, 2015, at 12:11 PM, Arunkumar Srinivasan
<<a href="mailto:aragorn168b@gmail.com">aragorn168b@gmail.com</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div 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; margin: 0px;">
Please go through the FAQ. This is outlined in the data.table FAQ
2.17 - smaller syntax differences between data.frame and
data.table.</div>
<div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;">
<br></div>
<div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;">DT[,
col] returns a vector because there’s no other way to return a
vector and users wanted a way to return a vector.</div>
<div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;">DT[,
“col”, with=FALSE] returns a data.table because data.table doesn’t
use the ‘drop’ argument. Plus you can always do DT[[“col”]] to
subset a column from data.frame/data.tables.</div>
<div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;">
‘drop’ has no other purpose, and it’s default value IMHO is a
mistake. I’m not sure about plans to implement it in data.table
(I’m not for it). Even if it were, you’d have to do: DT[, “col”,
with=FALSE, drop=FALSE] which seems quite bad in comparison to
DT[[“col”]].</div>
</div>
</blockquote>
<div><br></div>
<div><font face="Monaco"><span style="font-size: 14px;">Thanks for
this; the DT[['col']] suites my needs perfectly. I can see in
the examples (for ?data.table) and in the FAQ the examples that
show the column selection behavior using 'with'. This discussion
makes me wonder if the documentation for 'with' might benefit from
a small embellishment. Perhaps like this?</span></font></div>
<div><font face="Monaco"><span style="font-size: 14px;"><br></span></font></div>
<div>
<div style="font-size: 14px;">
<div><font face="Monaco">with:</font></div>
<div><font face="Monaco">By default with=TRUE and j is evaluated
within the frame of x; column names can be used as variables. When
with=FALSE j is a character vector of column names or a numeric
vector of column positions to select, and the value returned is
always a data.table. with=FALSE is often useful in data.table
to select columns dynamically.</font></div>
</div>
</div>
<div><br></div>
<div><font face="Monaco"><span style="font-size: 14px;">I think the
above faithfully describes the behavior I see, but I defer to you
to know what is best.</span></font></div>
<div><font face="Monaco"><span style="font-size: 14px;"><br></span></font></div>
<div><font face="Monaco"><span style="font-size: 14px;">Thanks
again,</span></font></div>
<div><font face="Monaco"><span style="font-size: 14px;">Ben</span></font></div>
<div><br></div>
<br>
<blockquote type="cite">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div id="bloop_sign_1424279289275484928" class="bloop_sign">
<div style="font-family:helvetica,arial;font-size:13px">
-- <br>
Arun</div>
</div>
<br>
<p style="">On 12 Feb 2015 at 22:28:08, Ben Tupper (<a href="mailto:btupper@bigelow.org">btupper@bigelow.org</a>) wrote:</p>
<blockquote type="cite" class="clean_bq">
<div><span>Hello,<br>
<br>
I would like to extract a column of a data.table, but I get
unexpected (to me) results when I specify a column
dynamically.<br>
<br>
DT <- data.table(ID = c("b","b","b","a","a","c"), a = 1:6, b =
7:12, c = 13:18)<br>
thisone = "a"<br>
<br>
str(DT[,a])<br>
# int [1:6] 1 2 3 4 5 6<br>
<br>
str(DT[,"a", with = FALSE])<br>
# Classes ‘data.table’ and 'data.frame': 6 obs. of 1
variable:<br>
# $ a: int 1 2 3 4 5 6<br>
# - attr(*, ".internal.selfref")=<externalptr><br>
<br>
str(DT[, thisone, with = FALSE])<br>
# Classes ‘data.table’ and 'data.frame': 6 obs. of 1
variable:<br>
# $ a: int 1 2 3 4 5 6<br>
# - attr(*, ".internal.selfref")=<externalptr><br>
<br>
I can't noodle out from the help why the latter two don't produce a
vector as the first one does. I'm looking at this online resource
<a href="http://www.rdocumentation.org/packages/data.table/functions/data.table">
http://www.rdocumentation.org/packages/data.table/functions/data.table</a>
and it doesn't seem like the description of with points to having
two different results.<br>
<br>
"with By default with=TRUE and j is evaluated within the frame of
x; column names can be used as variables. When with=FALSE, j is a
vector of names or positions to select, similar to a data.frame.
with=FALSE is often useful in data.table to select columns
dynamically."<br>
<br>
How should I extract a single column dynamically to retrieve a
vector?<br>
<br>
Cheers and thanks,<br>
Ben<br>
<br>
> sessionInfo()<br>
R version 3.1.0 (2014-04-10)<br>
Platform: x86_64-apple-darwin13.1.0 (64-bit)<br>
<br>
locale:<br>
[1]
en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8<br>
<br>
attached base packages:<br>
[1] stats graphics grDevices utils datasets methods base<br>
<br>
other attached packages:<br>
[1] data.table_1.9.5 devtools_1.6.1<br>
<br>
loaded via a namespace (and not attached):<br>
[1] chron_2.3-45 evaluate_0.5.5 formatR_1.0 httr_0.5 knitr_1.7
RCurl_1.95-4.1 stringr_0.6.2<br>
[8] tools_3.1.0<br>
<br>
Ben Tupper<br>
Bigelow Laboratory for Ocean Sciences<br>
60 Bigelow Drive, P.O. Box 380<br>
East Boothbay, Maine 04544<br>
<a href="http://www.bigelow.org">http://www.bigelow.org</a><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<a 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><br>
</span></div>
</blockquote>
</div>
</blockquote>
</div>
<br>
<div apple-content-edited="true">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div class="" style="font-size: 13px;"><span class="Apple-style-span" style="border-collapse: separate; font-family: Monaco; border-spacing: 0px;">
<font class="Apple-style-span" face="Helvetica">Ben Tupper<br>
Bigelow Laboratory for Ocean Sciences<br>
60 Bigelow Drive, P.O. Box 380<br>
East Boothbay, Maine 04544<br>
<a href="http://www.bigelow.org">http://www.bigelow.org</a></font></span></div>
</div>
</div>
</div>
</div>
</div>
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; font-family: Courier;">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Courier; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">
<br class=""></span></div>
</div>
<br class="Apple-interchange-newline"></div>
<br class="Apple-interchange-newline"></div>
<br class="Apple-interchange-newline"></div>
<br class="Apple-interchange-newline"></div>
<br class="Apple-interchange-newline">
<br class="Apple-interchange-newline"></div>
<br></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>