Reputation: 23
I have a vector of sample names:
names <- c("ABCdef", "ABCdef", "ABCdef")
How do I use regular expressions and gsub to return:
"def", "def", "def"
?
I.E., how do I write a gsub command that replaces the full names with only the lower-case letters in the name?
Upvotes: 2
Views: 24
Reputation: 2009
You can use the following to remove all upper case letters in a string:
names <- c("ABCdef", "ABCdef", "ABCdef")
gsub("[[:upper:]]*", "", names)
[1] "def" "def" "def"
Upvotes: 1