0
I have two tables of data. I would like to replace the Nas in Table1 with the values in Table2 using two reference columns that are in the two tables. I would like to replace only os Nas. Example:
Table1
State | Shop | shopping |
---|---|---|
SP | E01 | 5 |
SP | E02 | IN |
RJ | E01 | IN |
MT | E03 | IN |
Table2
State | Shop | shopping |
---|---|---|
SP | E01 | 3 |
SP | E02 | 10 |
RJ | E01 | 9 |
RJ | E02 | 7 |
MT | E03 | 4 |
Tabela1 <- structure(list(
Estado = structure(c(3L, 3L, 2L, 1L), .Label = c("MT", "RJ", "SP"), class = "factor"),
Loja = structure(c(1L, 2L, 1L, 3L), .Label = c("E01", "E02", "E03"), class = "factor"),
compras = c(5L, NA, NA, NA)), class = "data.frame", row.names = c(NA, -4L))
Tabela2 <- structure(list(
Estado = structure(c(3L, 3L, 2L, 2L, 1L), .Label = c("MT", "RJ", "SP"), class = "factor"),
Loja = structure(c(1L, 2L, 1L, 2L, 3L), .Label = c("E01", "E02", "E03"), class = "factor"),
compras = c(3L, 10L, 9L, 7L, 4L)), class = "data.frame", row.names = c(NA, -5L))
Welcome to Sopt. Always provide the example in a format that is easily read by anyone who wants to help you. See this topic on how to generate reproducible examples in R: https://answall.com/questions/264168/quais-as-principais-fun%C3%A7%C3%b5es-to-create-an-example-m%C3%adnimo-reproduce%C3%advel-em-r
– Carlos Eduardo Lagosta