<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 class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, May 17, 2013 at 9:42 AM, Alexandre Sieira <span dir="ltr"><<a href="mailto:alexandre.sieira@gmail.com" target="_blank">alexandre.sieira@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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">
<br></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"><font face="Courier New">> dt = data.table(a=c(1, 2, 3), b=c(4, 5, 6))</font></p><p style="margin:0px"><font face="Courier New">> dt</font></p><p style="margin:0px">
<font face="Courier New"> a b</font></p><p style="margin:0px"><font face="Courier New">1: 1 4</font></p><p style="margin:0px"><font face="Courier New">2: 2 5</font></p><p style="margin:0px"><font face="Courier New">3: 3 6</font></p>
<p style="margin:0px"><font face="Courier New">> str(dt[,a])</font></p><p style="margin:0px"><font face="Courier New"> num [1:3] 1 2 3</font></p><p></p><div><div><div> </div></div></div><div><br></div><div>However, if I don't, no such luck:</div>
<div><br></div><div><div><font face="Courier New">> colname="a"</font></div><div><font face="Courier New">> str(dt[,colname,with=F])</font></div><div><font face="Courier New">Classes ‘data.table’ and 'data.frame':<span style="white-space:pre-wrap"> </span>3 obs. of 1 variable:</font></div>
<div><font face="Courier New"> $ a: num 1 2 3</font></div><div><font face="Courier New"> - attr(*, ".internal.selfref")=<externalptr> </font></div></div><div><br></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><br></div><div>Thank you!</div><span class="HOEnZb"><font color="#888888"><div><br></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></font></span></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" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br></blockquote></div><br></div>