I would like to recode some identifiers, from upper case to lower case.
I am not sure what the issue is here.
n = c(\'AFD.434\', \'BSD.23\', \'F234
Your gsub call replaces each occurrence with the literal string "[[:lower:]]".
The simplest solution is to not use regular expressions; simply use tolower()
(as already mentioned in the comments / other answers).
One possible approach with regular expressions is the usage of Perl extended mode and the \L
modifier to convert to lowercase:
gsub(pattern = '([[:upper:]])', perl = TRUE, replacement = '\\L\\1', n)
This approach
(...)
to "remember" the match\1
to refer to the match in the replacement string\L
modifier to convert the match to lowercaseSee the online help for gsub
for further details.