I have a column of data in a R data frame that has values such as:
Blue-#105
Green-#8845
Yellow-#5454
Blue-#999
I want to remove the last number part (starting at -#) so that Blue-#999 and Blue-#105 are consider the same thing when plotting. How could I accomplish this?
Use regular expressions:
Here we say that all strings starting with
-#(where the comment char#needs to be escaped) and followed by whatever — which is.*in regular expression lingo: any char (the dot) repeated as many times as it fits (the star) — will get replaced by the empty string, or in other words, removed.