سؤال

I have many elements in a column in the format:

Var.24.22918699

Which need to be changed to

Var-24-22918699

Is there an easy way to do this R?

Thanks!

هل كانت مفيدة؟

المحلول

There sure is. gsub is used to replace specific characters in a string using regular expressions.

> x <- "Var.24.22918699"    
> gsub("[.]", "-", x)
## [1] "Var-24-22918699"

نصائح أخرى

Another option:

x <- "Var.24.22918699"  
chartr('.', '-', x)
# [1] "Var-24-22918699"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top