[datatable-help] na.omit in data.table after scale

Alexander Chernyakov alexander.chernyakov at gmail.com
Thu Oct 25 22:33:50 CEST 2012


There seems to be a problem with returning a matrix type (even though it's
single column) when using the := operator. data.table didn't complain so I
couldn't diagnose the problem right away.  Here is what happened:

 require(data.table)
    x <- data.table(a=1:10)
    x[,a:=scale(a)]
    #    [,1]
    # 1: -1.4863011
    # 2: -1.1560120
    # 3: -0.8257228
    # 4: -0.4954337
    # 5: -0.1651446
    # 6:  0.1651446
    # 7:  0.4954337
    # 8:  0.8257228
    # 9:  1.1560120
    #10:  1.4863011
    na.omit(x)
    Error in `[.data.table`(object, !omit) :
      i is invalid type (matrix). Perhaps in future a 2 column matrix could
return a list     of elements of DT (in the spirit of A[B] in FAQ 2.14).
Please let datatable-help know if     you'd like this, or add your comments
to FR #1611.

Doing as.vector(scale(*)) solves the problem.  It might be worthwhile to
put a warning in data.table when this occurs since I only was able to find
it by chance.

Thanks,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20121025/38870aee/attachment.html>


More information about the datatable-help mailing list