str_sub Function of stringr Package (2 Examples) | Extract & Replace Substring of Character String

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

library("stringr") # Load stringr package

x <- "example_xxx_string" # Create example string
str_sub(string = x, start = 8, end = 12) # Extract substring

str_sub(string = x, start = 8, end = 12) <- " character " # Replace substring
x # Print updated string

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

I've used `str_sub` to extract, but never considered replacing/coercing a string. Picking up helpful little nuggets like this is why I watch and recommend all these short daily vids. Thanks for keeping up the content!

douglaspage
Автор

This is very helpful. How can you replace special characters like hypen (-), underscore(_) or quote(") within a string to space. Eg James-Leleji to James Leleji or Good_food to Good food.
Basically removing the special characters to be replaced by a space
Thanks

jamesleleji
visit shbcf.ru