我试图在
data.table
set.seed(1)
dtX <- data.table(
"x.unit" = rnorm(10,0,1),
"y.line" = rnorm(10,0,1),
"z.line" = rnorm(10,0,1))
我可以通过手动指定列来完成此操作:
dtX[, maxVal := max(c(y.line,z.line)), by = 1:10]
但在我的真实数据中,我有很多列有长而复杂的名称;我希望避免手动将它们全部写出来。我有一个焦点列向量(
focalCol
)我想我可以用
..
focalCols <- colnames(dtX)[grepl(".line" , colnames(dtX))]
dtX[, maxVal := max(..focalCols), by = 1:10]
有没有
-我可以引用
数据表
进行计算?
Type of RHS ('character') must match LHS ('double'). To check and coerce would impact performance too much for the fastest cases. Either change the type of the target column, or coerce the RHS of := yourself (e.g. by using 1L instead of 1)