I am trying to remove all text after "-" including the "-" such as "Albany-Schenectady, Allentown-Bethlehem" etc.
I tried using Gsub, but having trouble getting the code to work.
#What I tried to make work
gsub("(.*)-.*", "\\1",
I am trying to remove all text after "-" including the "-" such as "Albany-Schenectady, Allentown-Bethlehem" etc.
I tried using Gsub, but having trouble getting the code to work.
#What I tried to make work
gsub("(.*)-.*", "\\1",
That's an incomplete line of code and not really even on the right track for what you've described. This should work.
gsub("-.*", "", vector)
The first argument tells it to grab the hyphen and everything after it to be replaced by the second argument, an empty string. The third argument is the vector you're performing the operation on.