如何使语法正确的名称

时间:2013-08-07 17:30:34

标签: r

如何修改此内容,以便添加_(下划线)代替.(点)作为其默认值。

> make.names(c("a and b", "a-and-b"), unique = TRUE)
[1] "a.and.b"   "a.and.b.1"

I am looking for the following result 
"a_and_b"   "a_and_b_1"

1 个答案:

答案 0 :(得分:8)

您可以将make.namesgsub

括起来
gsub("\\.", "_", make.names(c("a and b", "a-and-b"), unique = TRUE))
# [1] "a_and_b"   "a_and_b_1"