data.table 小插图定义了特殊符号 .BY
作为
.BY is a list containing a length 1 vector for each item in by. This can be useful when by is not known in advance. The by variables are also available to j directly by name; useful for example for titles of graphs if j is a plot command, or to branch with if() depending on the value of a group variable.
这个描述让我感到困惑。我如何以及何时使用.BY
?即使是图表标题?为什么将其添加为特殊符号?
example("data.table")
没有任何示例,我在 data.table wiki 页面上也没有找到任何示例。我也不知道如何在堆栈溢出上搜索 data.table 和 .BY 用法。我不断收到使用 by
的点击data.table
中的运算符
最佳答案
这是一个简单的示例,展示了如何将 .BY
传递给进一步的参数,例如绘图标题。使用内置 mtcars
数据:
mtcars <- as.data.table(mtcars)
layout(1:3)
mtcars[, plot(mpg, main=paste("Cylinders:", as.character(.BY))), by=cyl]
关于r - R data.table `.BY` 运算符如何使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40122918/