In R, the toupper()
function is used to convert string characters to upper case, whereas, the tolower()
function is used to convert string characters to lower case.
The casefold()
function, on the other hand, is used to convert string characters to upper or lower case, depending on the value of the upper
parameter assigned to it.
Syntax | Parameter value | Return value |
---|---|---|
toupper(x) | x : The string object |
A string object in upper case |
tolower(x) | x : The string object |
A string object in lower case |
casefold(x, upper) | x : The string object |
A string object in lower case or upper case |
upper : The Boolean value for case conversion |
# creating a string objectthisstring <- c("I love R language")# implementing the toupper() functionmystring1 <- toupper(thisstring)# implementing the tolower() functionmystring2 <- tolower(thisstring)# implementing the casefold() function for UPPER CASEmystring3 <- casefold(thisstring, upper=TRUE)# printing the stringsmystring1mystring2mystring3
thisstring
.toupper()
function on the string variable thisstring
. We assign the result to another variable mystring1
.tolower()
function on the string variable thisstring
. We assign the result to another variable mystring2
.casefold()
function on the string variable thisstring
. We assign the result to another variable mystring3
.mystring1
variable.mystring2
variable.mystring3
variable.# creating a string objectsthisstring <- c("I love R language")anotherstring <- c("It is so easy to LEARN!")# implementing the toupper() functionmystring1 <- toupper(c(thisstring, anotherstring))# implementing the tolower() functionmystring2 <- tolower(c(thisstring, anotherstring))# implementing the ccasefold() function for lower casemystring3 <- casefold(c(thisstring, anotherstring), upper=FALSE)# printing the stringsmystring1mystring2mystring3
thisstring
and anotherstring
.toupper()
function on the concatenation of both string variables thisstring
and anotherstring
. We assign the result to another variable mystring1
.tolower()
function on the concatenation of both string variables thisstring
and anotherstring
. We assign the result to another variable mystring2
.casefold()
function on the concatenation of both string variables thisstring
and anotherstring
. We assign the result to another variable mystring3
.mystring1
.mystring2
.mystring3
.