1

我正在使用非常有趣的 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"
)

我知道这行不通,但这是要走的路吗?

4

1 回答 1

1

是的,如果我理解正确的话,这可以用inclusionsand来完成exclusions。虽然格式有点时髦,但要求所有内容都是list.

library(rpivotTable)
data(HairEyeColor)
rpivotTable(
  data = HairEyeColor,
  rows = "Hair",
  cols="Eye",
  vals = "Freq",
  aggregatorName = "Sum",
  rendererName = "Table",
  inclusions = list(
    "Hair" = list("Red")
  )
)
于 2016-02-04T18:38:07.543 回答