[datatable-help] unique.data.frame should create a copy, right?
Ricardo Saporta
saporta at scarletmail.rutgers.edu
Thu Aug 1 22:12:54 CEST 2013
Amazing!! Thanks Steve, that's gonna come very much in handy
-Rick
On Thu, Aug 1, 2013 at 12:58 PM, Steve Lianoglou
<lianoglou.steve at gene.com>wrote:
> Hi,
>
> On Thu, Aug 1, 2013 at 12:27 AM, Arunkumar Srinivasan
> <aragorn168b at gmail.com> wrote:
> > Steve,
> >
> > Yes, exactly. If you dint have to subset the data.table as in your
> example,
>
> Not sure what subsetting (or not) has to do with it, but ...
>
> > the equivalent operation would be to set the key of DT1 to NULL and then
> > doing `unique` and storing it in DT2 and then setting the key back to
> "A" on
> > DT1.
> >
> > And it'd be nice to be able to do: `unique(DT1, usekey=FALSE)` or
> something
> > like that so that we don't have to NULL and set the key of DT1.
>
> Ask and you shall receive :-)
>
> I added a `use.key=TRUE` parameter to unique.data.table and
> duplicated.data.table which is in SVN revision 888. This runs the
> relevant functions on the data.table as if it were not keyed at all.
>
> R> DT1 <- CJ(A=0:1,B=1:6,D0=0:1,D=0:1)[D>=D0]
> R> setkey(DT1,A)
> R> DT2 <- unique.data.frame(DT1[,-which(names(DT1)%in%'B'),with=FALSE])
> R> dt2 <- unique(DT1[,-which(names(DT1) %in% 'B'),with=FALSE],
> use.key=FALSE)
> R> all.equal(DT2, dt2, check.attributes=FALSE)
> [1] TRUE
>
> The all.equal test will fail when check.attributers is TRUE because
> dt2 is still keyed by 'A'.
>
> R> key(DT1)
> [1] "A"
>
> R> key(DT2)
> NULL
>
> R> key(dt2)
> [1] "A"
>
> Hope that covers it,
> -steve
>
> --
> Steve Lianoglou
> Computational Biologist
> Bioinformatics and Computational Biology
> Genentech
> _______________________________________________
> 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/20130801/12d5be56/attachment.html>
More information about the datatable-help
mailing list