简单的问题:
我想在我的 DT 上使用data.table::setorder,但我不能按组执行此操作。是否可以 ?
在此示例中,我订购了整个 DT :
DT = data.table(a=rep(c('C', 'A', 'D', 'B', 'E'), each = 4), b=sample(1:1000,20))
setorder(DT, b)
DT
Run Code Online (Sandbox Code Playgroud)
但我想保持固定。
谢谢 !
从我的data.table DT.in,我想创建所有交叉连接组合,但不仅CJ(_all_my_var_).
我需要执行这样的事情:
CJ(var1)
CJ(var1, var2)
CJ(var1, var2, var3)
...
Run Code Online (Sandbox Code Playgroud)
这是我的代表:
library(data.table)
set.seed(999)
DT.in <- data.table(lvl1 = rep('AA', 200),
code = sample(c('D44', 'J21'), 200, replace = TRUE),
var = sample(c('Z3R', 'TR5', 'JKL', 'FR5', 'TFX'), 200, replace = TRUE),
test = sample(c('ONE', 'TWO', 'THREE', 'FOUR', 'FIVE', 'SIX', 'SEVEN'), 200, replace = TRUE))
foo.1 <- DT.in[, .(new = CJ(lvl1, unique = TRUE))]
foo.2 <- DT.in[, .(new = CJ(lvl1, code, unique = TRUE))]
foo.3 <- DT.in[, .(new = CJ(lvl1, …Run Code Online (Sandbox Code Playgroud) 在 Azure Databricks 环境中,我发现了软件包SparkR和sparklyr.
从我的笔记本中SparkR,我设法连接到数据库:
library(SparkR)
DW <- sql("select * from mydb.sometable")
Run Code Online (Sandbox Code Playgroud)
它运行良好,但 SparkR 语法似乎与经典 R 语法相差太远(根据我的说法)。
所以我想尝试一下sparklyr,但我无法访问同一个数据库:
library(sparklyr)
sc <- spark_connect(method="databricks")
test <- spark_read_table(sc, "mydb.sometable")
Error : org.apache.spark.sql.AnalysisException: It is not allowed to add database prefix ...
Run Code Online (Sandbox Code Playgroud)
有什么问题吗?
谢谢 !!