Created
October 29, 2015 09:39
-
-
Save Nicktz/aa1d771dcac92f7b10d5 to your computer and use it in GitHub Desktop.
Using GSUB - Fairtreegists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All strings before the _:
gsub("_.*","", files)