<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div dir="ltr">dt[row.num,][[<a href="http://col.name/">col.name</a>]] is indeed the solution.  And works of course for data.frames, too.  Maybe it should be added to the FAQ #1.3.</div><div dir="ltr">Thank you!</div><div><br><div><div>On May 8, 2013, at 4:00 PM, Frank Erickson <<a href="mailto:FErickson@psu.edu">FErickson@psu.edu</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">For your first question, this should work:<div><br></div><div>dt[row.num,][[<a href="http://col.name/">col.name</a>]]<br></div><div><br></div><div style="">For the second question, I guess your problem goes away if you aren't using an (all but) NULL data.table.</div>
<div style=""><br></div><div style=""><div>dt <- data.table(x=1,y=1)</div><div>nr <- data.table(NA,NA)</div><div><br></div><div>rbind(dt,nr,use.names=FALSE)</div><div>#    x  y</div><div>#1:  1  1</div><div>#2: NA NA</div>
<div><br></div><div style="">So, if you're dynamically growing your data.table from nothing, you'll only have to assign the colnames once, after the data.table becomes non-empty. I've read that R is pretty inefficient at dynamically growing things, ...as you say, it's a copy operation, right?</div>
<div style=""><br></div><div style="">I hope this helps.</div><div style=""><br></div><div style="">Best,</div><div style=""><br></div><div style="">Frank</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 8, 2013 at 11:31 AM, David Kulp <span dir="ltr"><<a href="mailto:dkulp@dizz.org" target="_blank">dkulp@dizz.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I must be doing something stupid.  I'd like to get a vector from a data.frame column using with=FALSE instead of a single-column data.table.<br>

<br>
dt <- data.table(x=1:10,y=letters[1:10])<br>
<a href="http://col.name/" target="_blank">col.name</a> <- 'y'<br>
row.num <- 5<br>
print(dt[row.num,y])  # returns a vector with the letter 'e'.  OK.<br>
print(dt[row.num,list(y)])  # returns a data.table.  OK.<br>
print(dt[row.num, <a href="http://col.name/" target="_blank">col.name</a> ,with=FALSE])  # returns a data.table... no list syntax here but I don't get a vector back.  Not OK.<br>
<br>
The best I can do is<br>
<br>
unlist(as.list(dt[row.num, <a href="http://col.name/" target="_blank">col.name</a> ,with=FALSE]))<br>
<br>
which seems rather hackish.<br>
<br>
I've read the FAQ and I'm stymied.  v1.8.8.  Any help?<br>
<br>
----<br>
<br>
While I've got your attention, I might as well ask another stupid question.  I can't insert new rows automagically.<br>
<br>
dt[11] <- c(11,'k')<br>
<br>
Although I can do<br>
<br>
df <- as.data.frame(dt)<br>
df[11,] <- c(11,'k')<br>
<br>
So I figure you want me to use rbind, even though rbind.data.table is probably a copy operation.<br>
<br>
dt <- rbind(dt, list(x=11,y='k'))<br>
<br>
But I'd like to start with an empty data.table and programmatically add chunks of rows as I run out of space.  So I generate a data.table of NA values and rbind.  E.g., here I want to add 5 new rows to the 2 column table.<br>

<br>
dt <- data.table(x=numeric(), y=character())<br>
new.rows <- lapply(1:2, function(c) { rep(NA, 5) })<br>
<br>
dt <- rbind(dt, new.rows, use.names=FALSE)<br>
<br>
According to the documentation, rbind is supposed to copy by position if use.names=FALSE, but it doesn't retain the column names.  This worked in v1.8.2.  Then I upgraded and it stopped working.  I know I can fix this by labeling the columns of new.rows, but I'm guessing that there's a much better way to simply allocate a new chunk of rows to a growing table and I didn't see any info online.<br>

<br>
Thanks in advance!!<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" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
</blockquote></div><br></div>
</blockquote></div><br></div></div></body></html>