substr
In this page:
substr
substr(x, start, stop) extracts a substring between the given character positions, inclusive on both ends, using 1-based indexing. substr() can also be used on the left side of an assignment to replace part of a string in place. This is R's built-in way to slice strings by position.
Note: Unlike many languages, substr()'s stop index is inclusive -- substr("hello", 1, 3) gives "hel", including position 3.
Example: substr
text <- "Hello, R World!"
cat(substr(text, 1, 5), "\n")
cat(substr(text, 8, 8), "\n")
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: