Master
Store No. Online Pressure MON TUE WED ... Hours
1 0.2 50 0 0 0 ... 53
2 0.8 20 0 0 0 ... 30
3 1.2 10 0 0 0 ... 20
...
Hours
Branch No. Day ... Time
1 MON 7.50
1 TUE 6.00
1 WED 8.50
3 MON 2.00
3 TUE 1.00
3 WED 2.50
...
The idea is I want to populate the days of the week "Mon", "Tue", "Wed"...etc in the 'Master' table from the data in the 'Hours' Table
How would I go about matching the Branch No. with the Store No. and then matching the 'day' data with the corresponding day in 'Master' columns. So the output of the Master should be as follows
Store No. Online Pressure MON TUE WED ... Hours
1 0.2 50 7.50 6.00 8.50 ... 53
2 0.8 20 0 0 0 ... 30
3 1.2 10 2.00 1.00 2.50 ... 20
...
It should do it for every row until all matched.
I apologise if I have explained poorly but I am new to R so only just learning my way around. I appreciate any help or edits welcome if it helps explain the problem to others
merge(
Master[!names(Master) %in% Hours$Day],
reshape(Hours,
direction = "wide",
idvar = "Branch No.",
timevar = "Day"),
by.x = "Store No.",
by.y = "Branch No.",
all = TRUE
)
Warm regards