Chaining - R

0

I have two date frames, one containing product data and one containing store data, but I do not have reference variables between them (which would not allow me an inner join), my need is to present for each of these products in question the code of each of the stores, as in the case below:

LOJA Produto

1    camera 

1    Smartphone

1    TV

2    camera

2    Smartphone

2    TV

.    .

.    .

. .

.

    
asked by anonymous 07.08.2017 / 15:08

2 answers

2

If your information is similar to what is in the expected result,

LOJA = 1:3
Produtos = c("camera", "Smartphone", "TV")

A merge resolves.

dados <- merge(LOJA, Produtos)
library(dplyr)
dados <- arrange(dados, x)
names(dados) <- c("LOJA", "Produtos")

Here the result of the above code

  LOJA   Produtos
     1     camera
     1 Smartphone
     1         TV
     2     camera
     2 Smartphone
     2         TV
     3     camera
     3 Smartphone
     3         TV
    
07.08.2017 / 15:38
3

With Rafael's data, it will be simpler to use the expand.grid function.

LOJA = 1:3
Produtos = c("camera", "Smartphone", "TV")

res <- expand.grid(LOJA = LOJA, Produtos = Produtos)[, 2:1]
res
    
07.08.2017 / 17:50