substr & substring Functions in R (3 Examples) | Extract & Replace Certain Characters of String

preview_player
Показать описание
Example R code of this video:

##### Example data
x1 <- "hello this is a string" # Create example vector

##### Example 1
substr(x1, start = 7, stop = 13) # Apply substr
substring(x1, first = 7, last = 13) # Apply substring

##### Example 2
substr(x1, start = 7) # Apply substr without stop condition
substring(x1, first = 7) # Apply substring without last condition

##### Example 3
x2a <- x1 # Duplicate example vector for 2nd example
x2b <- x1 # Another duplicate

substr(x2a, start = 1, stop = 5) <- "heyho" # Replace first word via substr function
x2a

substring(x2b, first = 1) <- "heyho" # Replace first word via substr function
x2b
Рекомендации по теме
Комментарии
Автор

Good videos .... exploring this channel

rrrprogram
join shbcf.ru