简体   繁体   English

NA / NaN / Inf in data.table 1.9.2

[英]NA/NaN/Inf in data.table 1.9.2

After checking the new feature of data.table 1.9.2, I'm not quite clear about the new feature of manipulation of NA/NaN/Inf. 在检查了data.table 1.9.2的新功能之后,我不太清楚操作NA / NaN / Inf的新功能。

The news: 新闻:

NA, NaN, +Inf and -Inf are now considered distinct values, may be in keys, can be joined to and can be grouped. NA,NaN,+ Inf和-Inf现在被认为是不同的值,可以是键,可以加入并可以分组。 data.table defines: NA < NaN < -Inf data.table定义:NA <NaN <-Inf

I don't know what does it mean by "can be joined to and can be grouped" 我不知道“可以加入并可以分组”是什么意思

DT <- data.table(A=c(NA,NA,1:3), B=c("a",NA,letters[1:3]))

Now we have NAs in both column A and B, 现在我们在A列和B列都有NA,

But I'm lost a little how to proceed, and what the purpose of this new feature is. 但我失去了一些如何继续,这个新功能的目的是什么。 Could you provide an example to illustrate this? 你能提供一个例子来说明这一点吗?

Thanks a lot! 非常感谢!

In previous versions of data.table NA, NaN,Inf values could exist in the key, but you could not join or use binary scan to select these rows in a consistent manner with other key values. 在以前版本的data.table NA, NaN,Inf值可能存在于密钥中,但您无法join或使用二进制扫描以与其他键值一致的方式选择这些行。

See Select NA in a data.table in R and data.table subsetting by NaN doesn't work for examples of SO questions that deal with these issues (and you can trace the history through the answers to Feature requests within the data.table project) 请参阅R中的data.table中的选择NANaN的data.table子集不适用于处理这些问题的SO问题的示例(您可以通过data.table项目中的功能请求的答案跟踪历史记录) )

Now, in 1.9.2 (and above) such things will work. 现在,在1.9.2(及以上)中,这样的事情会起作用。

# an example data set
DT <- data.table(A = c(NA,NaN,Inf,Inf,-Inf,NA,NaN,1,2,3), 
              B =letters[1:10], key = 'A')
# selection using binary search
DT[.(Inf)]
#     A B
# 1: Inf c
# 2: Inf d
DT[.(-Inf)]
#       A B
# 1: -Inf e
# note that you need to use the right kind of NA
DT[.(NA_real_)]
#     A B
# 1: NA a
# 2: NA f
DT[.(NaN)]
#      A B
# 1: NaN b
# 2: NaN g
# grouping works
DT[,.N,by=A]
#       A N
# 1:   NA 2
# 2:  NaN 2
# 3: -Inf 1
# 4:    1 1
# 5:    2 1
# 6:    3 1
# 7:  Inf 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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