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!
name_item |
---|
Apple Inc-Sales |
Orange-Inc-Sales |
Apple-Orange-Inc-Sales |
Apple-Orange-Mango-Inc-Sales |
Apple Inc-Profit |
Orange-Inc-Profit |
Apple-Orange-Inc-Profit |
Apple-Orange-Mango-Inc-Profit |
library(tidyverse)
toy_data <- tibble(
name_item = c(
"Apple Inc-Sales", "Orange-Inc-Sales", "Apple-Orange-Inc-Sales", "Apple-Orange-Mango-Inc-Sales",
"Apple Inc-Profit", "Orange-Inc-Profit", "Apple-Orange-Inc-Profit", "Apple-Orange-Mango-Inc-Profit"
)
)