R – String Upper-case

To convert String to upper-case in R language, call toupper() function and pass the string as argument. toupper() returns a new string with all the characters of the input string converted to upper-case.

Examples

In the following example, we take a string value in str variable, and convert this string to upper-case using toupper() function.

example.R

str <- 'Hello World'
result <- toupper(str)
print(result)

Output

% Rscript example.R
[1] "HELLO WORLD"

If the characters are already in upper-case, then the input string is returned as is.

example.R

str <- 'HELLO WORLD'
result <- toupper(str)
print(result)

Output

% Rscript example.R
[1] "HELLO WORLD"
ADVERTISEMENT

Conclusion

In this R Tutorial, we have learned to use toupper() function to convert a given string to upper-case in R programming language.