简体   繁体   中英

R data.table package and complex values

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM