How to capitalize the first letter of all words in a character string in the R programming language. More details: [ Ссылка ]
R Code of this video:
my_string <- "hello this is my string" # Create example string
##### Example 1
gsub("(^|[[:space:]])([[:alpha:]])", "\\1\\U\\2", # Uppercase with Base R
my_string,
perl = TRUE)
##### Example 2
install.packages("stringi") # Install stringi package
library("stringi") # Load stringi package
stri_trans_totitle(my_string) # Apply stri_trans_totitle function
# "Hello This Is My String"
##### Example 3
install.packages("tools") # Install tools package
library("tools") # Load tools package
toTitleCase(my_string) # Apply toTitleCase function
# "Hello this is My String"
Ещё видео!