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

Matthew Dowle mdowle at mdowle.plus.com
Fri Oct 26 12:06:14 CEST 2012


Alex,

Thanks a lot for reporting. Agreed. Have filed a bug report and updated
the S.O. question.

https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2333&group_id=240&atid=975

http://stackoverflow.com/questions/13076509/why-error-from-na-omit-after-running-scale-in-r-in-data-table

Matthew


> 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
> _______________________________________________
> 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



More information about the datatable-help mailing list