我正在使用非常有趣的html小部件rpivotTable。我知道如何预选作为行或列添加到数据透视表中的变量,但我真正需要的是预选这些变量的某些值。
作为我的意思的一个例子,我使用小插图页面中的代码:
library(rpivotTable)
data(HairEyeColor)
rpivotTable(
data = HairEyeColor, rows = "Hair",cols = "Eye", vals = "Freq",
aggregatorName = "Sum", rendererName = "Table",
sorters = "function(attr) {
var sortAs = $.pivotUtilities.sortAs;
if (attr == "Hair"){
return sortAs(["Red", "Brown", "Blond", "Black"]);}
}", width = "100%", height = "400px"
)
如果我想要,例如预先选择"Hair"变量的值"红色",是否可以在此脚本中执行此操作?像这样:
library(rpivotTable)
data(HairEyeColor)
rpivotTable(
data = HairEyeColor, rows = "Hair",cols = "Eye", vals = "Freq",
aggregatorName = "Sum", rendererName = "Table", sorters = "
function(attr) {
var sortAs = $.pivotUtilities.sortAs;
if (attr == "Hair") { return select(["Red"]); }
}", width = "100%", height = "400px"
)
我知道这行不通,但这是要走的路吗?
是的,如果我理解正确,这可以通过inclusions
和exclusions
来完成。 格式有点时髦,要求一切都是list
。
library(rpivotTable)
data(HairEyeColor)
rpivotTable(
data = HairEyeColor,
rows = "Hair",
cols="Eye",
vals = "Freq",
aggregatorName = "Sum",
rendererName = "Table",
inclusions = list(
"Hair" = list("Red")
)
)