Search notes:

R: basic string manipulation

str = "The Foo and the Bar went up the Baz, but didn't succeed"

# { nchar - number of characters

nchar(str)
# [1] 55

# }

# { tolower / toupper / casefold - convert to lower/upper case

str = "Foo Bar Baz"
tolower(str)
# [1] "foo bar baz"

toupper(str)
# [1] "FOO BAR BAZ"

casefold(str)
# [1] "foo bar baz"

casefold(str, upper = TRUE)
# [1] "FOO BAR BAZ"

# }

# { chartr - character translation

chartr('aou', 'AOU', 'Foo, Bar, Baz')
# [1] "FOO, BAr, BAz"

# }

# { abbreviate - abbreviate strings

abbreviate(c('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'), minlength=2)
#   Monday   Tuesday Wednesday  Thursday    Friday  Saturday
#     "Mn"      "Ts"      "Wd"      "Th"      "Fr"      "St"

# }

# { substr - replace substrings

substr(paste0(letters, collapse=""), 10, 13)
# [1] "jklm"

# }
Github repository about-r, path: /examples/basic_string_manipulation.R

See also

String related R functions
Printing characters
tolower() and toupper()

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758207331, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/examples/basic-string-manipulation(90): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78