Skip to content
Prev 359937 / 398503 Next

assign

You are not using that function as it was designed to be used.  You should read the help for gsub...

?gsub

And if you don't know what the term "regular expression pattern" that is mentioned there means then you will probably need to study one of the many fine tutorials that are available on the Web on that topic to understand how

gsub( "^.*-([^-]+)-.*$", "\\1", c( "junk-01-more", "stuff-17-" ) )

matches the entire string (^ to $) while capturing (parentheses) one or more non-dash characters ([^-]+) between the first dash and the second dash and substituting that "first capture" in place of the entire string. 

Note that the regular expression only needs one \ before the 1 but the R parser requires you to "escape" that with another \ to get that one \ into memory.

And while you are studying,  be sure to read and heed the R Mailing Lists Posting Guide mentioned in every post on this list,  because you used HTML format which tends to mess up R code examples.