[datatable-help] Extract Single Column as Vector
Alexandre Sieira
alexandre.sieira at gmail.com
Fri May 17 17:11:53 CEST 2013
It works perfectly for me with the syntax Eduard mentioned. Thank you very much for the quick response!
--
Alexandre Sieira
CISA, CISSP, ISO 27001 Lead Auditor
"The truth is rarely pure and never simple."
Oscar Wilde, The Importance of Being Earnest, 1895, Act I
On 17 de maio de 2013 at 12:02:50, Arunkumar Srinivasan (aragorn168b at gmail.com) wrote:
Eduard, are we discussing the same thing again :)? Wasn't this somehow your question as well.. the discrepancy between:
dt[, a] and dt[, "a", with=FALSE].
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.
Alexandre, as of now, it could be done as Eduard points out.
Arun
On Friday, May 17, 2013 at 4:59 PM, Eduard Antonyan wrote:
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.
On Fri, May 17, 2013 at 9:42 AM, Alexandre Sieira <alexandre.sieira at gmail.com> wrote:
Sorry if this is a basic question.
I'm using R 3.0.0 and data.table 1.8.8. The documentation for 'j' states that "A single column or single expression returns that type, usually a vector."
I am able to obtain this behavior if I know the column name in advance:
> dt = data.table(a=c(1, 2, 3), b=c(4, 5, 6))
> dt
a b
1: 1 4
2: 2 5
3: 3 6
> str(dt[,a])
num [1:3] 1 2 3
However, if I don't, no such luck:
> colname="a"
> str(dt[,colname,with=F])
Classes ‘data.table’ and 'data.frame': 3 obs. of 1 variable:
$ a: num 1 2 3
- attr(*, ".internal.selfref")=<externalptr>
If there a way to extract an entire column as a vector if I have the column name as a character scalar?
Thank you!
--
Alexandre Sieira
CISA, CISSP, ISO 27001 Lead Auditor
"The truth is rarely pure and never simple."
Oscar Wilde, The Importance of Being Earnest, 1895, Act I
_______________________________________________
datatable-help mailing list
datatable-help at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
_______________________________________________
datatable-help mailing list
datatable-help at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20130517/181104e7/attachment.html>
More information about the datatable-help
mailing list