data.table中的字符不支持Gforce min [英] Gforce min not supported for character in data.table

查看:92
本文介绍了data.table中的字符不支持Gforce min的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用data.table 1.9.4取字符向量的最小值时,得到以下错误:

When trying to take the min of a character vector using data.table 1.9.4, I get the following error:

Type 'character' not supported by GForce min (gmin). 
Either add the prefix base::min(.) or turn off 
GForce optimization using options(datatable.optimize=1)

公平的,但这打破了我现有的许多代码!我可以使用 options(datatable.optimize = 1)关闭这个优化。仍然,有没有反正简单地使用 base :: min 如果 is.character == TRUE ,否则GForce优化?

Fair enough, but this breaks a lot of my existing code! I can turn off this optimization using options(datatable.optimize=1). Still, is there anyway to simply use base::min if is.character == TRUE, and GForce optimization otherwise?

推荐答案

commit 1734 data.table v1.9.5 a>。

require(data.table) ## 1.9.5
set.seed(1L)
DT = data.table(x=sample(3,10,TRUE), y=sample(letters[1:3], 10,TRUE))
options(datatable.verbose=TRUE)

DT[, .(min(y), max(y)), by=x]
# Detected that j uses these columns: y 
# Finding groups (bysameorder=FALSE) ... done in 0secs. bysameorder=FALSE and o__ is length 10
# lapply optimization is on, j unchanged as 'list(min(y), max(y))'
# GForce optimized j to 'list(gmin(y), gmax(y))'
#    x V1 V2
# 1: 1  a  c
# 2: 2  a  c
# 3: 3  b  c

如果不正确,请回信。

这篇关于data.table中的字符不支持Gforce min的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆