To convert a string to uppercase in R, you can use the toupper()
function.
In this example,
"Hello World"
to the variable str1
.toupper()
function to str1
to convert it to uppercase and store the result in the variable upperCaseStr1
.toupper()
function returns a new string with all characters converted to uppercase.upperCaseStr1
.str1 <- "Hello World"
upperCaseStr1 <- toupper(str1)
print(paste("Uppercase of given string is:", upperCaseStr1))
Uppercase of given string is: HELLO WORLD
In this example,
"apple"
to the variable str2
.toupper()
function to str2
to convert it to uppercase and store the result in the variable upperCaseStr2
.toupper()
function returns a new string with all characters converted to uppercase.upperCaseStr2
.str2 <- "apple"
upperCaseStr2 <- toupper(str2)
print(paste("Uppercase of given string is:", upperCaseStr2))
Uppercase of given string is: APPLE
In this tutorial, we learned How to convert String to Uppercase in R language with well detailed examples.