Skip to content

Instantly share code, notes, and snippets.

@webbedfeet
Created March 9, 2017 02:08
Show Gist options
  • Select an option

  • Save webbedfeet/ae7c0dbdad49e4bf25124ec4b742a46b to your computer and use it in GitHub Desktop.

Select an option

Save webbedfeet/ae7c0dbdad49e4bf25124ec4b742a46b to your computer and use it in GitHub Desktop.
Inserting a character at a particular point in a string using R
# To put a particular character _ after the 10th position in a string
gsub('^([a-z]{10})([a-z]+)','\\1_\\2', x)
# or
library(stringr)
str_replace(x, '^([a-z]{10})([a-z]+]','\\1_\\2')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment