I have a list of strings which look like that:
categories <- "|Music|Consumer Electronics|Mac|Software|"
However, I only want get the first string. In this case Music(without |). I tried:
sub(categories, pattern = " |", replacement = "")
However, that does not give me the desired result. Any recommendation how to correctly parse my string?
I appreciate your answer!
UPDATE
> dput(head(df))
structure(list(data.founded_at = c("01.06.2012", "26.10.2012",
"01.04.2011", "01.01.2012", "10.10.2011", "01.01.2007"), data.category_list = c("|Entertainment|Politics|Social Media|News|",
"|Publishing|Education|", "|Electronics|Guides|Coffee|Restaurants|Music|iPhone|Apps|Mobile|iOS|E-Commerce|",
"|Software|", "|Software|", "|Curated Web|")), .Names = c("data.founded_at",
"data.category_list"), row.names = c(NA, 6L), class = "data.frame")
subare in the wrong order. 2) You need to escape|withpattern = "\\|"3)subwill only replace characters, not split strings.