Search notes:

R function: substring

#
#   S.a. 
#     ../examples/basic_string_manipulation.R
#
#

text = '1234567890'
substring(text, 0, 5)
# [1] "12345"

substring(text, 1, 5)
# [1] "12345"

substring(text, 2, 5)
# [1] "2345"

substring(text, -4, 3)
# [1] "123"

substring(text, 3, 3)
# [1] "3"

substring(text, 3, 7) <- 'xy'
text
# [1] "12xy567890"

substring(text, 6, 7) <- 'abcd'
text
# [1] "12xy5ab890"


# With recycling
a <- c('foo', 'bar', 'baz', 'one', 'two', 'three')
substring(a , 2, 2) <- c(',', '_')
a
# [1] "f,o"   "b_r"   "b,z"   "o_e"   "t,o"   "t_ree"
Github repository about-r, path: /functions/substring.R

See also

String related R functions, substr
Index to (some) R functions

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...', 1745902414, '3.148.229.54', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/functions/substring(76): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78