Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

Duplicate rows based on splitting condition

$
0
0

I want to duplicate rows based on a splitting condition ideally in SQL or Excel. Is there an easy way to do this? Listed an example of the output I'm expecting below.

structure(list(key = 1:3, Sales_channel = structure(c(1L, 1L, 
2L), .Label = c("online", "shop"), class = "factor"), Product = structure(3:1, .Label = c("bus & boat", 
"bus & cinema", "bus & zoo"), class = "factor"), quantity = c(1, 
2, 1)), class = "data.frame", row.names = c(NA, -3L))

I want to get the following:

  key Sales_channel quantity values
1   1        online        1    bus
2   1        online        1    zoo
3   2        online        2    bus
4   2        online        2 cinema
5   3          shop        1   boat
6   3          shop        1    bus

In effect, I want to split each string by "& ", and then pivot the table.


Viewing all articles
Browse latest Browse all 201894

Trending Articles