Crystal_K
Crystal_K

Reputation: 23

How do I replace a vector of words with different cases, with the lower case characters only?

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

Answers (1)

NM_
NM_

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

Related Questions