To convert the first character in a string to uppercase in R, you can use the toupper()
function.
In this example,
str1
with a value of "hello world"
.str1
to uppercase using the toupper()
function.str1 <- "hello world"
modifiedStr1 <- paste(toupper(substr(str1, 1, 1)), substr(str1, 2, nchar(str1)), sep="")
print(paste("Modified string is:", modifiedStr1))
Modified string is: Hello world
In this example,
str2
with a value of "r"
.str2
to uppercase using the toupper()
function.str2 <- "r"
modifiedStr2 <- paste(toupper(substr(str2, 1, 1)), substr(str2, 2, nchar(str2)), sep="")
print(paste("Modified string is:", modifiedStr2))
Modified string is: R
In this tutorial, we learned How to convert First Character in String to Uppercase in R language with well detailed examples.