[datatable-help] Unexpected behavior in setnames()
Arunkumar Srinivasan
aragorn168b at gmail.com
Fri Nov 8 21:37:26 CET 2013
Sure, here's an example of what I was trying to explain:
Suppose:
DT <- data.table(x=1:5, y=1:5, x=6:10)
Then,
DT[, c(1,3), with=FALSE] # gives correct subset
DT[, c("x", "x"), with=FALSE] # gives column 1 twice - wrong
DT[, .SD, .SDcols=c("x", "x")] # gives column 1 twice - wrong result
DT[, .SD, .SDcols=c(1,3)] # gives column 1 twice - wrong result - but *should provide right result if "ambiguity" is the only concern.
Arun
On Friday, November 8, 2013 at 9:29 PM, Steve Lianoglou wrote:
> > Steve,
> > Maybe, but it's just getting started :) - we now have to decide what's
> > ambiguous!
> >
>
>
> So close, yet so far ...
>
> > Ex: Is subsetting by column number considered ambiguous (By definition of
> > ambiguous, probably not)? But then it'd be inconsistent with subsetting when
> > column names are provided.. So, should we prioritise consistency over
> > function in this scenario?
> >
>
>
> Sorry, can you provide examples of each?
>
> I'd imagine doing anything by column number is unambiguous, but I'm
> not sure how you can subset by column index and by column name in a
> "similar" fashion.
>
> I mean dt[[1]] should work no matter what, dt[['a']] would work only
> if there is only one column named 'a' ... but I don't think this is
> what you are talking about?
>
> Sorry if I'm being obtuse,
>
> -steve
>
> --
> Steve Lianoglou
> Computational Biologist
> Bioinformatics and Computational Biology
> Genentech
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20131108/6a257c87/attachment.html>
More information about the datatable-help
mailing list