简体   繁体   English

更改 R 中 `table()` 输出中的字符名称?

[英]Changing the character name in the output of `table()` in R?

I was wondering how I could change the name foo appearing in the top-left corner of the output of b in my R code below to boo ?我想知道如何将下面 R 代码中b输出左上角的名称foo更改为boo

foo <- sample(rep(1:3, 20))
b <- table(foo)
b

I tried the following with no success:我尝试了以下但没有成功:

names(b) <- "boo"

You can set the character name using the parameter dnn.您可以使用参数 dnn 设置角色名称。

foo <- sample(rep(1:3, 20))
b <- table(foo, dnn = "boo")
print(b)
#boo
# 1  2  3 
#20 20 20 

https://www.rdocumentation.org/packages/base/versions/3.5.1/topics/table https://www.rdocumentation.org/packages/base/versions/3.5.1/topics/table

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

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