I have a data.frame like this:
names
---------------
car
truck or lorry
bike
I need this output, spliting each string, using " or " in this example:
names |norm
---------------|-------
car |car
truck or lorry |truck
truck or lorry |lorry <-- "truck or lorry" has to be repeated
bike |bike
My attempt was to use strsplit
, but I can't repeat the first column value to get the result
df <- data.frame(names=c("car","truck or lorry","bike"),stringsAsFactors=FALSE)
df$norm <- strsplit(df$names, " or ")