[datatable-help] unique.data.frame should create a copy, right?

Steve Lianoglou lianoglou.steve at gene.com
Wed Jul 31 20:02:11 CEST 2013


Hi all,

On Wed, Jul 31, 2013 at 9:09 AM, Arunkumar Srinivasan
<aragorn168b at gmail.com> wrote:
> Ricardo,
>
> You read my mind.. :) I was thinking of the same as well.. Whether the
> community agrees or not would be interesting as well. It could save trouble
> with "alloc.col" manually.

It's easy enough to add -- just to be sure, the behavior required from
the OP would be equivalent to calling unique on a data.table that has
no key, right? For example, instead of this:

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[,gah:=1] # warning: I should have made a copy, apparently

You could just do:

R> DT1 <- CJ(A=0:1,B=1:6,D0=0:1,D=0:1)[D>=D0]
R> DT2 <- unique(DT1[, -which(names(DT1)%in%'B'), with=FALSE])
R> DT2[,gah:=1]

Right?

-steve

-- 
Steve Lianoglou
Computational Biologist
Bioinformatics and Computational Biology
Genentech


More information about the datatable-help mailing list