[datatable-help] DT[NA] now returns 1 row of NA
Matthew Dowle
mdowle at mdowle.plus.com
Mon Aug 23 21:20:57 CEST 2010
Hello everyone,
Before change :
> DT = data.table(a=1:3,v=1:3)
> DT
a v
[1,] 1 1
[2,] 2 2
[3,] 3 3
> DT[NA]
a v
[1,] NA NA
[2,] NA NA
[3,] NA NA
That was consistent with data.frame :
> DF = data.frame(a=1:3,v=1:3)
> DF[NA,]
a v
NA NA NA
NA.1 NA NA
NA.2 NA NA
The reason for that was that NA is logical, followed by standard
recycling.
Branson mentioned it here and it got me thinking :
http://r.789695.n4.nabble.com/Ran-into-infinite-loop-when-setting-key-sorting-columns-with-NA-tp2315205p2315207.html
It came up on r-help recently here too :
http://r.789695.n4.nabble.com/NA-values-in-indexing-tp1692067p1692067.html
Now, after the change :
> DT[NA]
a v
[1,] NA NA
>
I think this makes more sense than having to know to need
DT[NA_integer_]. I can't think of any useful purpose for returning the
entire table as NA; if DT is large it would create a large copy and that
shouldn't be so easy to do by accident. A single NA row is almost
certainly what was intended.
Everything is up for discussion though so if I've missed anything please
let me know and this can always be rolled back.
Matthew
More information about the datatable-help
mailing list