Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make syntactically correct names

Tags:

r

How can I modify this so that it add _ (underscore) in place of . (dot) as its default value.

> 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"
like image 275
learner Avatar asked Feb 15 '23 15:02

learner


1 Answers

You could enclose make.names with gsub:

gsub("\\.", "_", make.names(c("a and b", "a-and-b"), unique = TRUE))
# [1] "a_and_b"   "a_and_b_1"
like image 55
sgibb Avatar answered Feb 23 '23 06:02

sgibb