<div>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:</div>
<div><br></div><div> require(data.table)</div><div> x <- data.table(a=1:10)</div><div> x[,a:=scale(a)]</div><div> # [,1] </div><div> # 1: -1.4863011</div><div> # 2: -1.1560120</div><div> # 3: -0.8257228</div>
<div> # 4: -0.4954337</div><div> # 5: -0.1651446</div><div> # 6: 0.1651446</div><div> # 7: 0.4954337</div><div> # 8: 0.8257228</div><div> # 9: 1.1560120</div><div> #10: 1.4863011</div><div> na.omit(x)</div>
<div> Error in `[.data.table`(object, !omit) : </div><div> 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.</div>
<div><br></div><div>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.</div><div><br></div><div>Thanks,</div><div>
Alex</div>