<div>@Matthew,
</div><div><br></div><div>On another note, are there plans to implement "drop=T/F" in data.table?</div>
<div><div><br></div><div>Arun</div><div><br></div></div>
<p style="color: #A0A0A8;">On Saturday, May 18, 2013 at 5:21 PM, Arunkumar Srinivasan wrote:</p>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
<span><div><div>
<div>
<pre>Matthew wrote "..the length of an input shouldn't change the type of the output (only the type of the input should be able to change the type of the output)."</pre><pre><font face="Helvetica">That's a very nice way to put it.</font></pre>
</div>
<div><div><br></div><div>Arun</div><div><br></div></div>
<p style="color: #A0A0A8;">On Saturday, May 18, 2013 at 5:18 PM, Matthew Dowle wrote:</p><blockquote type="cite"><div>
<span><div><div>
<p> </p>
<p>And FAQ 2.17 has a little more on that :</p>
<pre> "In [.data.frame we very often set drop=FALSE. When we forget, bugs can arise in edge cases<br>where single columns are selected and all of a sudden a vector is returned rather than a single<br>column data.frame. In [.data.table we took the opportunity to make it consistent and drop<br>drop."</pre>
<pre> </pre>
<pre>If it helps to know, I also use DT[["somename"]] quite a bit. </pre>
<pre> </pre>
<pre>Matthew</pre>
<p> </p>
<p>On 18.05.2013 10:04, Matthew Dowle wrote:</p><blockquote type="cite"><div><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<p> </p>
<pre>All good points. The thinking here has this mind :<br><br> myvars = c("col1","col2")<br> DT[, myvars, with=FALSE]<br><br>We don't want the type of the result to depend on whether myvars is length 1 or not. Otherwise we may end up with surprises (in production code for example) if myvars becomes length 1 in future. That's a strong principle that data.table follows : the length of an input shouldn't change the type of the output (only the type of the input should be able to change the type of the output).<br><br>I've just changed those two parts of ?data.table (thanks for highlighting) :<br><br>was :<br> "... or (when with=FALSE) same as j in [.data.frame."<br>now :<br> "... or (when with=FALSE) a vector of names or positions to select."<br><br>Matthew</pre>
<p> </p>
<p>On 17.05.2013 20:34, Ricardo Saporta wrote:</p><blockquote style="padding-left: 5px; border-left: #1010ff 2px solid; margin-left: 5px; width: 100%;">
<div dir="ltr"><span style="font-family: arial,sans-serif; font-size: 13.333333969116211px;">Hm... Eddi does seem to have a point here. While I agree with Frank that once you're used to it, it is rather straightforward to deal with, I can see why one would have the expectation of a vector. ie, that the last of the following `identical` statements should evaluate to `TRUE`</span>
<div style="font-family: arial,sans-serif; font-size: 13.333333969116211px;">
<div> df <- as.data.frame(dt)</div>
<div> > identical(df[, "a"], dt[, get("a")])</div>
<div> [1] TRUE</div>
<div> > identical(df[, "a"], dt[["a"]])</div>
<div> [1] TRUE</div>
<div> > identical(df[, "a"], dt[, "a", with=FALSE])</div>
<div> [1] FALSE</div>
<div> rm(df)</div>
</div>
<div style="font-family: arial,sans-serif; font-size: 13.333333969116211px;">-Rick</div>
<div><br clear="all">
<div>
<div style="color: #222222; font-family: arial,sans-serif; font-size: 13px; background-color: #ffffff;">
<div style="font-size: 13px;">Ricardo Saporta</div>
<div style="font-size: 13px;">Graduate Student, Data Analytics</div>
<div style="font-size: 13px;"><span style="font-size: 13px;">Rutgers University, New Jersey</span></div>
<div style="font-size: 13px;"><span style="font-size: 13px;">e: </span><a style="color: #1155cc; font-size: 13px;" href="mailto:saporta@rutgers.edu">saporta@rutgers.edu</a></div>
</div>
</div>
<br><br>
<div>On Fri, May 17, 2013 at 4:26 PM, Eduard Antonyan <span><<a href="mailto:eduard.antonyan@gmail.com">eduard.antonyan@gmail.com</a>></span> wrote:<br><blockquote type="cite"><div>
<div dir="ltr">Well, looking at the documentation:
<div>j: A single column name, single expresson of column names, <code>list()</code> of expressions of column names, an expression or function call that evaluates to <code>list</code> (including <code>data.frame</code> and <code>data.table</code> which are <code>list</code>s, too), or <strong>(when <code>with=FALSE</code>) same as <code>j</code> in <code>[.data.frame</code>.</strong></div>
<div>...</div>
<div>with:<strong> </strong>By default <code>with=TRUE</code> and <code>j</code> is evaluated within the frame of <code>x</code>. The column names can be used as variables. <strong>When <code>with=FALSE</code>, <code>j</code> works as it does in <code>[.data.frame</code>.</strong></div>
<br>
<div><strong><br></strong></div>
<div>The bolded out part of the documentation doesn't match the actual behavior.</div>
</div>
<div>
<div>
<div><br><br>
<div>On Fri, May 17, 2013 at 2:44 PM, Frank Erickson <span><<a href="mailto:FErickson@psu.edu">FErickson@psu.edu</a>></span> wrote:<br><blockquote type="cite"><div>
<div dir="ltr">@Arun and eddi: This question has come up before.
<div><a href="http://r.789695.n4.nabble.com/Better-hacks-getting-a-vector-AND-using-with-inserting-chunks-of-rows-tt4666592.html">http://r.789695.n4.nabble.com/Better-hacks-getting-a-vector-AND-using-with-inserting-chunks-of-rows-tt4666592.html</a></div>
<div>(And I'm sure there are other times, too.) I can't say I've heard anyone arguing about it, though. :)</div>
<div>I guess it works that way because</div>
<div>...in dt[ ,a], j is an expression which evaluates to a vector</div>
<div>...in dt[,"a",with=FALSE] the option turns on the "you must want one or more columns" mode, translating j from "a" to list(a)</div>
<div>It's unintuitive if you're expecting data frame behavior (you know, drop=TRUE, as Arun mentioned), but if you've already seen dt[,list(a)], it shouldn't be much of a surprise. Adding the drop option, and maybe defaulting it to TRUE when with=FALSE might satisfy eddi's concern...?</div>
</div>
<div>
<div>
<div><br><br>
<div>On Fri, May 17, 2013 at 10:22 AM, Eduard Antonyan <span><<a href="mailto:eduard.antonyan@gmail.com">eduard.antonyan@gmail.com</a>></span> wrote:<br><blockquote type="cite"><div>
<div dir="ltr">I don't remember discussing this issue...? What is the conceptual difference between dt[, a] and dt[, "a", with = F] and what does 'drop' have to do with this??</div>
<div>
<div>
<div><br><br>
<div>On Fri, May 17, 2013 at 10:02 AM, Arunkumar Srinivasan <span><<a href="mailto:aragorn168b@gmail.com">aragorn168b@gmail.com</a>></span> wrote:<br><blockquote type="cite"><div>
<div>Eduard, are we discussing the same thing again :)? Wasn't this somehow your question as well.. the discrepancy between:</div>
<div>dt[, a] and dt[, "a", with=FALSE]. </div>
<div>There should be a drop=TRUE/FALSE option (as in the case of data.frame) that should be used when you use `with=FALSE`. Until then, the default option seems to be drop=FALSE, which results in a data.table.</div>
<div>Alexandre, as of now, it could be done as Eduard points out.</div>
<div>
<div>Arun</div>
</div>
<div>
<div>
<p style="color: #a0a0a8;">On Friday, May 17, 2013 at 4:59 PM, Eduard Antonyan wrote:</p><blockquote style="border-left-style: solid; border-width: 1px; margin-left: 0px; padding-left: 10px;">
<div>
<div>
<div dir="ltr">Use dt[[colname]], but this seems like a bug to me - I would've thought that dt[, a] and dt[, "a", with = F] should return the exact same thing.</div>
<div><br><br>
<div>On Fri, May 17, 2013 at 9:42 AM, Alexandre Sieira <span><<a href="mailto:alexandre.sieira@gmail.com">alexandre.sieira@gmail.com</a>></span> wrote:<br><blockquote style="padding-left: 5px; border-left: #1010ff 2px solid; margin-left: 5px; width: 100%;">
<div>
<div style="word-wrap: break-word;">
<p style="font-family: Helvetica,Arial; font-size: 13px; margin: 0px; line-height: auto;">Sorry if this is a basic question.</p>
<p style="font-family: Helvetica,Arial; font-size: 13px; margin: 0px; line-height: auto;"> </p>
<p style="font-family: Helvetica,Arial; font-size: 13px; margin: 0px; line-height: auto;"><span style="font-family: sans-serif; line-height: normal;">I'm using R 3.0.0 and data.table 1.8.8.</span><span style="font-family: sans-serif; line-height: normal;"> </span>The documentation for 'j' states that "<span style="font-family: sans-serif; line-height: normal;">A single column or single expression returns that type, usually a vector."</span></p>
<p style="font-family: Helvetica,Arial; font-size: 13px; margin: 0px; line-height: auto;"><span style="font-family: sans-serif; line-height: normal;"><br></span></p>
<p style="font-family: Helvetica,Arial; font-size: 13px; margin: 0px; line-height: auto;"><span style="font-family: sans-serif; line-height: normal;">I am able to obtain this behavior if I know the column name in advance:</span></p>
<p style="font-family: Helvetica,Arial; font-size: 13px; margin: 0px; line-height: auto;"><span style="font-family: sans-serif; line-height: normal;"><br></span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span>> dt = data.table(a=c(1, 2, 3), b=c(4, 5, 6))</span></p>
<p style="margin: 0px;"><span>> dt</span></p>
<p style="margin: 0px;"><span> a b</span></p>
<p style="margin: 0px;"><span>1: 1 4</span></p>
<p style="margin: 0px;"><span>2: 2 5</span></p>
<p style="margin: 0px;"><span>3: 3 6</span></p>
<p style="margin: 0px;"><span>> str(dt[,a])</span></p>
<p style="margin: 0px;"><span> num [1:3] 1 2 3</span></p>
<p> </p>
<div>However, if I don't, no such luck:</div>
<div>
<div><span>> colname="a"</span></div>
<div><span>> str(dt[,colname,with=F])</span></div>
<div><span>Classes ‘data.table’ and 'data.frame':<span style="white-space: pre-wrap;"> </span>3 obs. of 1 variable:</span></div>
<div><span> $ a: num 1 2 3</span></div>
<div><span> - attr(*, ".internal.selfref")=<externalptr> </span></div>
</div>
<div>If there a way to extract an entire column as a vector if I have the column name as a character scalar?</div>
<div>Thank you!</div>
<div><span style="font-family: helvetica,arial; font-size: 13px;"></span>
<div style="font-family: Helvetica; line-height: normal;">-- </div>
<div style="font-family: Helvetica; line-height: normal;"><span style="font-family: arial; font-size: small;">Alexandre Sieira</span><br style="font-family: arial; font-size: small;"><span style="font-family: arial; font-size: small;">CISA, CISSP, ISO 27001 Lead Auditor</span><br style="font-family: arial; font-size: small;"><br style="font-family: arial; font-size: small;"><span style="font-family: arial; font-size: small;">"The truth is rarely pure and never simple."</span><br style="font-family: arial; font-size: small;"><span style="font-family: arial; font-size: small;">Oscar Wilde, The Importance of Being Earnest, 1895, Act I</span></div>
</div>
</div>
<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></div>
</blockquote></div>
</div>
</div>
<div>
<div>_______________________________________________</div>
<div>datatable-help mailing list</div>
<div><a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a></div>
<div><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></div>
</div>
</div>
</blockquote></div>
</div>
</div></blockquote></div>
</div>
</div>
</div>
<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></div></blockquote></div>
</div>
</div>
</div>
</div></blockquote></div>
</div>
</div>
</div>
<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></div></blockquote></div>
</div>
</div>
</blockquote><p> </p>
<div> </div>
</div></blockquote><p> </p>
<div> </div>
</div></div></span>
</div></blockquote><div>
<br>
</div>
</div></div></span>
</blockquote>
<div>
<br>
</div>