简体   繁体   English

Deparse.level = 2 在 R

[英]Deparse.level = 2 in R

I need to know what deparse.level = 2 means and what it does to a table and everything I write makes me more confused.我需要知道 deparse.level = 2 的含义以及它对表的作用以及我写的所有内容都让我更加困惑。 Can anyone help me please?谁能帮帮我吗?

Thank you谢谢

I tried to apply the table without diparse.level and I can see the order of the table changes but it also adds labels so I cant undersdant what exactly it is meant to do我尝试在没有 diparse.level 的情况下应用表格,我可以看到表格的顺序发生了变化,但它也添加了标签,所以我无法理解它到底是什么意思

Not sure what you mean with the ordering part, but table(..., deparse.level = 2) makes the function willing to name the dimensions in the table things that are not symbols (variable names, basically) if an argument wasn't named in the call.不确定你对排序部分的意思,但是table(..., deparse.level = 2)使 function 愿意在表中命名不是符号的维度(基本上是变量名),如果参数不是'电话中没有提到姓名。 In effect it tries extra hard to assign names to the dimensions even if they're something like a function call, for example.实际上,它会更加努力地为维度分配名称,即使它们类似于 function 调用,例如。 See the Details and Examples in the next help text with ?table .使用?table查看下一个帮助文本中的详细信息和示例。


More detail:更多详情:

The documentation technically does explain it, but it's... a bit dense:该文档在技术上确实解释了它,但它......有点密集:

If the argument dnn is not supplied, the internal function list.names is called to compute the 'dimname names'.如果未提供参数 dnn,则调用内部 function list.names 来计算“dimname 名称”。 If the arguments in... are named, those names are used.如果 arguments in... 被命名,则使用这些名称。 For the remaining arguments, deparse.level = 0 gives an empty name, deparse.level = 1 uses the supplied argument if it is a symbol, and deparse.level = 2 will deparse the argument.对于剩余的 arguments,deparse.level = 0 给出一个空名称,deparse.level = 1 如果它是一个符号则使用提供的参数,deparse.level = 2 将解析参数。

There's a good example below that though:不过下面有一个很好的例子:

> a <- letters[1:3]
> table(a, sample(a))                    # dnn is c("a", "")
   
a   a b c
  a 0 0 1
  b 1 0 0
  c 0 1 0
> table(a, sample(a), deparse.level = 0) # dnn is c("", "")
   
    a b c
  a 1 0 0
  b 0 0 1
  c 0 1 0
> table(a, sample(a), deparse.level = 2) # dnn is c("a", "sample(a)")

   sample(a)
a   a b c
  a 1 0 0
  b 0 0 1
  c 0 1 0

Only in the last one is it willing to name a dimension "sample(a)".只有在最后一个中,它才愿意将维度命名为“sample(a)”。 In all those cases the second vector isn't given as a named argument, so it tries to figure out what symbol to use for it (with level 1, the default) or what text of any kind to use for it (with level 2).在所有这些情况下,第二个向量都没有作为命名参数给出,因此它试图找出用于它的符号(默认级别 1)或用于它的任何类型的文本(级别 2 ).


Even more:更:

And about what it means by "if it is a symbol," see ?is.symbol and ?deparse and the rabbit hole that leads to.关于“如果它是一个符号”的含义,请参阅?is.symbol?deparse以及通向的兔子洞。 It's not about how weird the name looks;这与名字看起来有多奇怪无关; you can do something like this, and it's fine with it at deparse level 1 since it is a symbol in this context:你可以做这样的事情,它在deparse level 1很好,因为它这个上下文中的一个符号:

> `sample(a)` <- sample(a)
> table(a, `sample(a)`)
   sample(a)
a   a b c
  a 0 0 1
  b 1 0 0
  c 0 1 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM