mercredi 6 juin 2018

R programming: ifelse on multiple tables

I am just venturing into R programming and finding my way around.

Lets say I have a table as below:

Store | Product | Sales
X | A | 2
X | B | 1
X | C | 3
Y | A | 1
Y | B | 2
Y | C | 5
Z | A | 3
Z | B | 6
Z | C | 2

I need to change the sales values of certain products based on another table. Please find below:

Product | Sales
A | 10
B | 7
C | 15

My final table should be:

Store | Product | Sales
X | A | 10
X | B | 7
X | C | 15
Y | A | 10
Y | B | 7
Y | C | 15
Z | A | 10
Z | B | 7
Z | C | 15

I have 2 methods of doing this now: 1) Using joins 2) Using an if-else statement inside a for loop to subset the

Is there any other way to do this more effectively and in fewer steps? Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire