Revisión | 4f3eb7ddb68f90e9058456698dccd1be05274b5a (tree) |
---|---|
Tiempo | 2023-01-11 20:53:12 |
Autor | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
I added a function to insert a character in a string at a given position.
@@ -7016,4 +7016,11 @@ | ||
7016 | 7016 | |
7017 | 7017 | } |
7018 | 7018 | |
7019 | - | |
7019 | +## See https://statisticsglobe.com/insert-character-pattern-in-string-r | |
7020 | + | |
7021 | +insert_char <- function(x, pos, insert) { # Create own function | |
7022 | + gsub(paste0("^(.{", pos, "})(.*)$"), | |
7023 | + paste0("\\1", insert, "\\2"), | |
7024 | + x) | |
7025 | +} | |
7026 | + |