I would like to use the separate() or any other function to generate two new variables, where one variable would contain company names and another would contain info names (Sales or Profit). Notice that a company name might contain one or more -. Thanks in advance!
The sep argument determines what character is used to separate the input into pieces. In this case, we want to use the last hyphen. I defined the last hyphen as "a hyphen after which there are no more hyphens". To understand the regular expression I used to represent that, I will work from the inside out.
[^-] means any character that is not a hyphen
[^-]+ means one or more of any character that is not a hyphen
The $ represents the end of the paragraph or input so
[^-]+$ means one or more of any character that is not a hyphen followed by the end of the input
The structure (?= ) represents text that follows whatever text the search engine is looking at but it does not count as part of what has been found. It is a look-ahead assertion. The entire regular expression
-(?=[^-]+$) means a hyphen followed by one or more of any character that is not a hyphen followed by the end of the input
That is a somewhat complicated way to say "the last hyphen".