R data.table package and complex values

纵饮孤独 提交于 2020-01-05 13:02:43

问题


I'm new to the data table package and so far its incredible! With one hitch...

data.table does not seem to like complex numbers. For example, the code:

DT <- data.table(x = as.complex(1:5))
DT[1]

produces the error:

Error in `[.data.table`(DT, 1) : Unknown column type 'complex'

I've searched high and low, and unless I am being a colossal idiot I can't find any information on this, except for an obscure github edit: github

Is this just a current limitation of the data.table package, or is it a known bug?

EDIT: Initially I thought updating to the development version as suggested by Richard had solved the issue, but a few steps down the line I was met with another error.

I have a large data table that is result of a fast fourier transform. I initially wrote a custom function to split its complex result into real, imaginary and absolute values to get around this bug. However, now I need these complex values again to do a second FFT, and here is where I get my issue.

I was getting another warning message from rbindlist which also said it didn't support complex columns, and in trying to write some reproducible code for this question, came across this new error:

stacktest<-data.table(x=complex(real=1:60, imaginary=-1:-60),y=LETTERS[1:10],z=rep(1:2,5))

setkey(stacktest, z)

Error in setkeyv(x, cols, verbose = verbose, physical = physical) : 
  Item 1 of list is type 'complex' which isn't yet supported

This is odd since I didn't get this error when using setkey on my actual dataframe which has a column containing just complex values, instead getting an error when trying to dcast, but if even this simple code doesn't work I wont bother showing you my other error!

I take it I'm just going to have to accept data.table isn't ready for complex numbers yet? Or by some chance is this the resurfacing of some old bug?

Thanks for your patience!


回答1:


It was a bug. Looks like it was fixed in the latest development version. You can install from github with package devtools.

Install instructions

packageVersion("data.table")
# [1] ‘1.9.5’
dt <- data.table(x = as.complex(1:5))
dt[1]
#       x
# 1: 1+0i


来源:https://stackoverflow.com/questions/32570742/r-data-table-package-and-complex-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!