Skip to content

Instantly share code, notes, and snippets.

@Nicktz
Created October 29, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicktz/aa1d771dcac92f7b10d5 to your computer and use it in GitHub Desktop.
Save Nicktz/aa1d771dcac92f7b10d5 to your computer and use it in GitHub Desktop.
Using GSUB - Fairtreegists
We uuse GSUB to change parts of a string.
This is particularly useful if we want to replace parts of a word or phrase.
It can be used as follows to, e.g., replace all the '/' by a '_' in data:
data[y,z]<-gsub("/","_", data[y,z])
To remove all parts of a string after a sign, we can also use gsub.
E.g., if we have naming conventions such as:
Meanreversion - JALSH/3Month/etc
Value - JALSH/3Month/etc
We can remove all parts of strings after the '-' using:
colnames(data) <- gsub("\ - .*","", colnames(data))
@Nicktz
Copy link
Author

Nicktz commented Dec 18, 2015

All strings before the _:

gsub("_.*","", files)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment