我正在使用非常有趣的 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”变量的值“Red”,是否可以在此脚本中执行此操作?就像是:
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"
)
我知道这行不通,但这是要走的路吗?