Master
StoreNumber Online Pressure MON TUE WED ... SUN ...
1 0.2 50 0 0 0 ... 0
2 0.8 20 0 0 0 ... 0
3 1.2 10 0 0 0 ... 0
...
Hours
BranchNumber 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
...
NB There are many branch numbers about 10,500 due to being 7 days in a week so one branch number may occur 7 times for each day of the week, but some may only have 6 or 5 etc.
The idea is I want to populate the days of the week "Mon", "Tue", "Wed"... "Sun" etc in the 'Master' table from the 'Time' data in the 'Hours' Table. The match should check that the StorenNumber matches the BranchNumber...then the day of the week, if there is 'Mon' in the hours table then it should match it to the column 'Mon' in the Master table.
So the output will look something like this
StoreNumber 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
...
As an example BranchNumber 2 doesnt exist in the Hours table so it should just skip each column and leaves the inputs as 0
I have tried the R based code below but am struggling to get an output...Once running the code I get zero errors but the Master Table remains unchanged and all days of the week columns remain as 0
merged <- Master%>% select(-
c("MON","TUE","WED","THU","FRI","SAT","SUN")) %>%
left_join(
Hours %>% pivot_wider(names_from = Day, values_from =
Time),
by = c("StoreNumber" = "BranchNumber"))
merged <- merged %>% replace(is.na(.),0)
Dput(Master)
Pressure = c(0, 0, 0, 0, 0, 0, 0, 0, 0.23, 0,
0.19, 0, 0, 0, 0.56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0.42, 0, 0, 0, 0, 0.37, 0, 0, 0.92, 0, 0, 0, 0,
0.04, 0.15, 0.12, 0.12, 0.06, 0.02, 0.19, 0.12, 0.08, 0.15,
0.02, 0.46, 0.25, 0.02, 0.17, 0.06, 0.25, 0.08, 0, 0.08,
0, 0.12, 0.23, 0.02, 0.04, 0.02, 0.15, 0, 0.02, 0.1, 0, 0,
0.04, 0.02, 0.23, 0.48, 0.19, 0.06, 0.02, 0.02, 0.08, 0.13,
0, 0.02, 0.08, 0.06, 0.15, 0.42, 0.06, 0.04, 0.04, 0.44,
0.06, 0.42, 0.06, 0.13, 0.46, 0, 0.81, 0.12, 0.25, 0.5, 0.06,
0.23, 0.02, 0.19, 0.33, 0, 0.06, 0.13, 0.12, 0.27, 0.04,
0.17, 0.13, 0.08, 0.12, 0.1, 0.21, 0.31, 0.17, 0, 0, 0.04,
0.1, 0.29, 0.13, 0.38, 0.15, 0.17, 0.58, 0.02, 0.02, 0.08,
1.15, 0.08, 0.1, 0.4, 0.58, 0.35, 0.12, 0.12, 0.5, 0.17,
0.6, 0.04, 0.06, 0.13, 0.12, 0.06, 0.19, 0.25, 0.06, 0.06,
0.1, 0, 0.29, 0.58, 0.02, 0.08, 1.4, 0.15, 0.21, 0.15, 0.1,
0.02, 0, 0, 0.08, 0, 0.02, 0.23, 0.1, 0.6, 0, 0.08, 0.37,
0, 0.17, 0.21, 0.44, 0.77, 0.33, 0.42, 0, 0.12, 0.12, 0.1,
0.12, 0.06, 0.02, 0.04, 0.17, 0.13, 0.02, 0.12, 0.25, 0.06,
0.04, 0.04, 0.17, 0.17, 0.6, 0.06, 0.37, 0, 0.15, 0.13, 0.08,
0.21, 0, 0.13, 0.02, 0.15, 0, 0.4, 0.23, 0.27, 0.08, 0.1,
0.19, 0.04, 0.02, 0.1, 0.17, 0.85, 0.56, 0, 0.56, 0.56, 0.06,
0.06, 0, 0.21, 0.02, 0.33, 0, 0.04, 0.13, 0.1, 0.12, 0, 0,
0.13, 0.17, 0.08, 0.02, 0.12, 0.06, 0.38, 0.21, 0.1, 0, 0.13,
0.17, 0, 0.1, 0.12, 0.17, 0, 0.42, 0.15, 0.15, 0.42, 0.04,
0.04, 0.69, 0.15, 0, 0, 0.17, 0.4, 0.23, 0.27, 0.04, 0.17,
0.06, 0, 0, 0.06, 0.21, 0.04, 0.29, 0.04, 0.19, 0, 0.19,
0.02, 0.02, 0.29, 0.35, 0.19, 0.23, 0.42, 0.02, 0.35, 0.29,
0.02, 0.17, 0.1, 0.06, 0.17, 0.1, 0.38, 0.02, 0.15, 0.17,
0.29, 0.04, 0.02, 0.38, 0.12, 0.17, 0.02, 0, 0.06, 0.12,
0.08, 0.13, 0.12, 0.1, 0.33, 0.23, 0.29, 0.31, 0.19, 0.17,
0, 0.33, 0.17, 0.38, 0.02, 0.21, 0.17, 0.19, 0.06, 0.29,
0.12, 0.02, 0.15, 0.13, 0.17, 0.25, 0.02, 0.15, 0.65, 0.48,
0.29, 0.02, 0.19, 0.29, 0.27, 0.06, 0.02, 0.29, 0.21, 0.15,
0.12, 0.19, 0.44, 0.1, 0.04, 0.12, 0.15, 0.27, 0.1, 0.15,
0.1, 0.06, 0.15, 0.06, 0.15, 0.13, 0.54, 0.19, 0.04, 0.33,
0.06, 0.25, 0.17, 0.29, 0.12, 0.25, 0.1, 0.31, 0.13, 0.1,
0.1, 0.02, 0.25, 0.02, 0.15, 0.13, 0.29, 0.15, 0.77, 0.1,
0.08, 0.38, 0.4, 0.02, 0.37, 0, 0.12, 0.27, 0.25, 0.46, 0,
0.02, 0.12, 0, 0.27, 0.02, 0, 0.13, 0.04, 0.08, 0.13, 0.25,
0.08, 0.06, 0, 0.06, 0.12, 0.33, 0.15, 0.67, 0.04, 0.31,
0.21, 0.19, 0.25, 0.27, 0.02, 0.1, 0.1, 0.06, 0.44, 0.35,
0.23, 0.1, 0.15, 0.21, 0.08, 0.02, 0.37, 0.27, 0.17, 0.1,
0.04, 0.19, 0.42, 0.27, 0.29, 0.63, 0.54, 0.29, 0.02, 0.44,
0.35, 1.35, 0, 0.4, 0.25, 0.04, 0.02, 0.02, 0.17, 0.19, 0.17,
0.1, 0.42, 0.13, 0.13, 0.1, 0.1, 0.06, 0.04, 0.04, 0.44,
0.06, 0.04, 0.1, 0.21, 0.06, 0.02, 0.19, 0.27, 0.44, 0.02,
0.17, 0.06, 0.02, 0.17, 0.15, 0.15, 0.15, 0.12, 0.02, 0,
0, 0.21, 0.02), Online = c(1.63, 2.6, 0.48, 1.9, 5.27, 1.23,
1.87, 4.56, 3.71, 2.4, 9.62, 1.15, 1.5, 1.96, 2.5, 10.37,
2.62, 7.44, 2.71, 1.48, 16.94, 3.92, 2.9, 4.44, 2.69, 6.04,
2.69, 1.44, 0.52, 0.48, 1.44, 0.85, 4.56, 1.81, 9.25, 3.12,
5.56, 2.33, 4.67, 2.54, 3.73, 1.63, 3.4, 1.9, 1.15, 1.08,
6.27, 2.23, 3.13, 2.02, 0.63, 3.31, 2.96, 4.56, 3.19, 2.62,
6.21, 8.6, 2.23, 2.33, 0.9, 2.6, 0.94, 1.58, 0.85, 3.38,
4.04, 6.46, 3.17, 4.79, 7.92, 6.58, 1.63, 5.88, 5.06, 6.42,
2.69, 4.4, 2.08, 2.81, 3.23, 1.6, 3.08, 5.77, 1.65, 2.56,
3.81, 4.08, 3.65, 5.06, 1.15, 1.15, 1.08, 3.77, 2.75, 2.6,
2.56, 4.37, 4.92, 2.12, 1.58, 0.1, 1.87, 1.44, 4.02, 2.5,
1.29, 2.33, 6.12, 4.62, 1.98, 5.77, 3.19, 0.9, 1.5, 9.77,
7.63, 5.37, 0.79, 1.17, 4.23, 2.81, 4.31, 2.71, 3.4, 6.38,
2.75, 1.23, 4.77, 2.4, 6.04, 0.58, 0.79, 8.08, 2.13, 1.75,
0.87, 2.19, 1.38, 2.54, 2.71, 1.65, 3.5, 1.85, 18.52, 2.08,
0.33, 3.19, 6.69, 1.06, 3.08, 1.81, 1.06, 0.48, 0.85, 3.65,
1.44, 1.63, 1.71, 3.5, 2.12, 9.62, 1.96, 7.48, 1.65, 3.19,
11.04, 1.81, 3.4, 3.73, 6.1, 0.9, 10.31, 4.46, 2.27, 1.17,
0.94, 2.02, 2.75, 6.38, 3.83, 4.98, 3.77, 2.71, 5.63, 1.21,
3.31, 0, 9.35, 5.56, 1.79, 6.15, 1.9, 3.4, 6.52, 0.63, 1.37,
4.25, 1.71, 0.69, 0.75, 1.23, 2.69, 2.02, 1.79, 3.56, 0.75,
0.75, 0.52, 1.21, 1.12, 0.69, 1.79, 4.56, 1.23, 4.83, 5.04,
2.38, 1.23, 5.4, 3.13, 2.62, 1.08, 13.38, 3.52, 5.19, 3.62,
1.08, 4.5, 10.19, 2.33, 4.73, 1.87, 9.4, 11.21, 1.65, 2.29,
2.9, 35.94, 3.19, 2.4, 1.79, 7.58, 5.4, 4.73, 1.21, 1.54,
1.75, 2.98, 2.27, 2.08, 2.08, 4.35, 5.85, 3.12, 1.63, 5.06,
1.65, 4.92, 4.77, 5.06, 5, 5.27, 8.75, 3.56, 5.77, 6.21,
10.13, 6, 7.69, 1.92, 3.81, 7.92, 1.63, 4.29, 3.46, 7.65,
8.35, 1, 6.27, 6.96, 2.17, 14.81, 10.65, 0.04, 2.54, 1.38,
0.85, 5.79, 3.5, 6.6, 6.04, 2.13, 4.04, 5.63, 4.94, 1.27,
2.5, 6.42, 4.83, 4.35, 3.19, 4.1, 1.38, 1.63, 2.4, 6.96,
0.63, 2.12, 8.65, 3.67, 1.9, 2.08, 5.46, 3.71, 1.69, 2.81,
0.6, 2.06, 5.1, 2.87, 5.27, 6.54, 2.56, 0.42, 0.33, 1.12,
1.06, 1.6, 1.37, 2.23, 1.08, 1.75, 0.6, 0.9, 5.1, 2.27, 0.73,
1.33, 1.06, 1.96, 1.98, 3.98, 1.75, 1.87, 9.73, 12, 1.15,
1.23, 3.29, 1.92, 6.06, 4.44, 2.48, 1.37, 5.58, 2.12, 1.81,
1.17, 0.27, 1.6, 4.85, 1.17, 2.48, 1.63, 2.17, 1.71, 4.15,
0.48, 1.44, 1.08, 4.67, 4.56, 0.52, 6.06, 1.63, 2.35, 1.23,
1.96, 14.35, 0.58, 1.54, 1.5, 1.9, 2.54, 2.48, 2.77, 19.6,
3.35, 0.73, 1.69, 1.17, 0.85, 3.23, 0.17, 2.27, 3.71, 2.27,
2.4, 1.37, 1.5, 2.02, 0.12, 0.25, 0.38, 17.13, 2.65, 0.31,
1.85, 3.13, 1.54, 3.38, 2.98, 3.71, 2.23, 4.58, 3.29, 1.02,
7.12, 1.96, 1.85, 0.85, 2.69, 1.81, 1.21, 1.06, 3.13, 1.44,
2.71, 3.4, 3.98, 3.08, 0.9, 5, 0, 0, 0, 0, 0, 2.06, 0.75,
5.25, 2.06, 3.38, 3.04, 7.9, 4.73, 1.44, 10.67, 0.06, 7.42,
2.19, 4.5, 2.44, 3.13, 3.52, 2.75, 0.27, 7.1, 5.63, 0.52,
1.15, 2.48, 2.48, 3.71, 1.6, 1.98, 2.06, 1.5, 4.56, 1.08,
0.25, 1.15, 4.79, 2.6, 4.73, 2.6, 0.15, 0.15, 5.27, 1.21,
5, 1.29, 3.38, 0.85, 2.27, 0, 0.73, 0.38, 0.38, 0.94, 0.38,
2.08, 1.71, 4.29, 0.94, 5.62, 2.23, 0.38, 1.23, 2.06, 0.65,
4.71, 2.19, 3.08, 1.21, 1.38, 2.06, 0.54, 0.81, 1.08, 4.35,
12.6, 8.98, 1.87, 1.58, 0.27, 0.46, 19.65, 0.38, 1.37, 2.06,
1.98, 0.31, 0.46, 0.6, 0.38, 0.31, 3.77, 2.5, 15.56, 5.27,
12.58, 7.33, 11.06, 9.33, 12.79, 15.29, 7.12, 7.23, 14.17,
12.06, 12, 6.54, 6, 15.35, 10.71, 14.69, 6.94, 6.12, 5.73,
7.17, 4.15, 15.77, 7.02, 12.75, 11.56, 8.12, 6.46, 7.12,
9.02, 11.04, 10.79, 10.08, 8.08, 8.21, 9.81, 8.92, 10.73,
10.15, 9.35, 8.62, 6.27, 13.23, 14.02, 14.13, 6.25, 7.37,
6.06, 21.4, 6.63, 7.1, 8.62, 17.29, 8.4, 7.44, 5.77, 10.77,
56.38, 9.77, 11.98, 8.9, 6.06, 5.77, 13.48, 14.23, 8.17,
9.62, 11.62, 6, 12.38, 7.42, 7.23, 5.79, 8.08, 8.35, 4.73,
7.58, 6.15, 6.88, 15.65, 13.02, 7.71, 18.33, 5.69, 4.5, 7.96,
5.35, 21.17, 4.29, 9.17, 13.96, 8.69, 8.5, 12.94, 7.1, 6.15,
19.94, 7.54, 13.9, 11.56, 11.4, 11.31, 19.6, 8.83, 11.19,
9.94, 7.5, 8, 6, 4.85, 6.15, 9.94, 8.02, 11.15, 15.13, 7.06,
10.37, 10.04, 27.02, 8.17, 13.6, 11.04, 11.15, 6.1, 4.37,
7.02, 15.5, 13.15, 7.75, 9.19, 11.48, 8.81, 10.23, 12.1,
5.96, 8.13, 12.48, 8.21, 9.44, 13.15, 9.54, 19.9, 4.71, 4.63,
23.63, 24.31, 10.79, 15.35, 12.79, 10.31, 20.85, 9.02, 15.04,
9.4, 4.63, 11.27, 5.96, 40.12, 8.77, 7.79, 8.27, 7.1, 11.62,
3.81, 5.67, 5.35, 8.6, 7.33, 7.6, 8.87, 17.77, 7.92, 5.9,
6.85, 12.54, 21.08, 15.08, 9.02, 3.98, 11.67, 32.79, 5.21,
5, 6.38, 10.31, 21.35, 18.06, 13.17, 16.52, 17.04, 10.4,
4.29, 21.19, 8.71, 8.75, 14.5, 5, 8.29, 9.19, 19.87, 4.5,
3.87, 6.73, 6.75, 22.87, 8.4, 13.38, 16.79, 3.31, 8.5, 12.48,
6.33, 10.25, 9.87, 6.04, 14.33, 6.04, 5.79, 5.63, 10.73,
13.58, 8.87, 11.88, 9.12, 12.21, 10.08, 7.5, 13.9, 10.92,
8.4, 9.65, 9.25, 13.75, 9.46, 12.33, 10.02, 98.77, 11.21,
5.77, 5.19, 12.9, 10.1, 10.56, 6.12, 6.17, 7.44, 2.08, 0.65,
2.92, 0.42, 4.1, 8.62, 1.37, 2.35, 2.56, 1.15, 2.17, 0.69,
4.02, 1.81, 1.37, 2.87, 3.29, 2.96, 1.42, 2.62, 0.48, 2.35,
5.27, 2.23, 1.38, 3.31, 8.87, 3.25, 2.98, 3.94, 2.13, 1.85,
5.19, 2.9, 2.23, 2.38, 0.9, 2.92, 0.96, 0.75, 2.33, 4.88,
4.08, 3.65, 7.87, 11.35, 2.83, 3.62, 3.12, 4.79, 4.62, 5.27,
5.25, 6, 2.29, 1.44, 1.06, 2.44, 1.42, 2.6, 4.67, 4.1, 1.06,
2.83, 2.87, 1.5, 1.5, 0.87, 0.73, 3.83, 2.71, 0.65, 2.35,
1.37, 4.23, 2.17, 1.81, 2.77, 1.23, 1.96, 1.37, 4.44, 3.35,
1.96, 2.33, 1.33, 1.38, 6.67, 2.75, 1.48, 2.62, 1.65, 2.29,
5, 1.81, 2.08, 1.27, 3.4, 1.42, 2.23, 0.37, 1.69, 2.23, 2.83,
0.69, 4.71, 1.85, 1.23, 2.71, 8.12, 1.87, 2.62, 0.85, 3.12,
4.88, 1.23, 2.13, 0.52, 4.73, 4.31, 1.23, 0.38, 0.48, 0.58,
1.27, 3.31, 12.46, 2.4, 5.13, 2.81, 2.87, 2.44, 6.69, 1.85,
5.1, 2.29, 4.35, 1.6, 3.25, 3.13, 1.98, 1.79, 2.87, 2.33,
4.31, 0.73, 0.46, 2.83, 1.06, 0.73, 3.94, 0.42, 6.48, 2.4,
5.37, 2.71, 3.38, 1.81, 1.87, 5.13, 0.87, 0.9, 3.38, 0.81,
1.06, 0.96, 0.63, 2.87, 1.5, 1.29, 4.1, 1.54, 2.13, 6.42,
3.17, 3.25, 2.44, 3.19, 1.81, 2.4, 3.83, 3.71, 2.71, 3.04,
15.13, 4.73, 3.17, 2.62, 8.69, 7.1, 2.13, 2.02, 1.42, 2.19,
3.44, 3.56, 3.67, 8.17, 0.63, 3.35, 1.9, 0.87, 1.75, 4.4,
7.12, 3.46, 4.56, 2.81, 1.08, 0.81, 2.27, 2.23, 0.94, 4.92,
3.44, 2.87, 2.65, 6.31, 2.5, 1.85, 1.44, 1.71, 1.15, 1.37,
0.31, 2.9, 3.5, 3.17, 0.48, 0.85, 1.65, 3.56, 6.81, 1.17,
0, 4.02, 2.71, 1.96, 3.44, 10.23, 2.98, 2.54, 4.1, 1.65,
2.4, 4.88, 2.75, 1.9, 2.75, 1.69, 5.37, 7.33, 6.06, 4.19,
1.6, 0.75, 6.63, 2.87, 3.77, 1.85, 1.69, 1.6, 4.85, 5.35,
2.65, 2.75, 2.83, 0.42, 4.88, 3.04, 9.44, 11.79, 4.79, 1.5,
3.52, 0.87, 1.71, 1.15, 1.02, 0.87, 3.35, 7.06, 4.19, 0.94,
0.63, 2.06, 4.62, 2.6, 1.29, 3.73, 4.25, 3.87, 4.23, 1.92,
6.15, 2.12, 4.83, 2.35, 2.29, 6.67, 1.38, 1.15, 1.54, 1.92,
1.75, 1.15, 0, 0, 2.96, 1.08, 0.17, 4.98, 3.5, 4.62, 1.65,
0.1, 2.92, 3.77, 1.65, 0, 1.69, 6.04, 3.88, 3.25, 2.44, 2.75,
1.63, 2.6, 3.04, 0.63, 2.06, 0.15, 0.63, 3.35, 1.15, 0.69,
2.5, 2.6, 0.96, 1.27, 3.6, 2.5, 3.77, 0.81, 0.96, 5.96, 1.12,
0.81, 0.85, 1.38, 4.1, 1.63, 1.69, 0.12, 5.62, 2.98, 3.44,
0.87, 3.17, 1.98, 2.92, 9.54, 0.06, 3.88, 0.81, 1.27, 0.46,
1.12, 2.13, 3.83, 8.83, 1.48, 7.23, 0.48, 1.58, 0.54, 3.12,
3.44, 0.54, 0.17, 3.6, 0.33, 0.81, 0.6, 0.37, 1.17, 2.6,
2.92, 1.81, 3.62, 2.98, 2.06, 4.35, 1.69, 0.37, 1.06, 2.23,
1.42, 0.73, 2.06, 1.38, 1.12, 2.19, 1.15, 0.6, 0.31, 3.83,
1.6, 3.98, 2.35, 13.9, 0.37, 1.85, 3.6, 2.19, 4.5, 0.42,
0.27, 4.23, 5.21, 4.04, 1.33, 5.06, 0, 10.35, 3.19, 2.33,
7.17, 0.52, 0.69, 4.04, 8.21, 7.44, 5.69, 3.5, 2.62, 7.42,
1.85, 4.02, 2.27, 16.15, 7.33, 1.42, 12.31, 3.04, 1.17, 3.17,
9.33, 4.71, 4.67, 4.46, 3.87, 0.21, 2.17, 6.73, 11.88, 2.98,
1.29, 15.87, 0.42, 1.6, 2.23, 1.21, 1.33, 2.81, 3.67, 3.13,
4.71, 6.21, 7.15, 1.44, 3.46, 3.04, 1.85, 1.37, 2.69, 3.71,
5.85, 1.12, 16.58, 2.9, 9.46, 4.58, 2.27, 5.15, 3.94, 2.38,
1, 4.52, 0.65, 1.87, 2.02, 0.15, 1.9, 16.31, 2.5, 4.08, 4.08,
5.21, 5.62, 3.62, 2.56, 1.63, 9.87, 0.63, 1.85, 3.19, 9.62,
3.71, 2.06, 4.79, 9.25, 5.96, 1.63, 2.27, 0.37, 2.9, 3.88,
4.08, 5.63, 5.94, 2.27, 3.38, 4.85, 2.4, 2.35, 0.52, 1.29,
3.52, 1.6, 4.77, 22.02, 3.94, 1.33, 1.33, 1.33, 14.63, 1.98,
6.12, 7.9, 1.5, 1.15, 5.85, 0.9, 2.17, 0.81, 2.17, 4.56,
2.23, 6.27, 10.58, 4.5, 7.96, 2.33, 6.25, 2.44, 3.02, 4.31,
6.58, 2.06, 3.5, 5.4, 0.69, 8, 1.71, 1.44, 0.85, 1.69, 7.54,
2.33, 1.37, 2.17, 2.92, 1.65, 1.69, 3.83, 3.35, 0.79, 3.4,
1.81, 0.81, 2.77, 3.12, 6.75, 1.6, 1.69, 2.54, 3.65, 3.65,
12.6, 3.29, 1.44, 1.65, 5.94, 6, 6.38, 1.48, 9.25, 1.21,
8.98, 2.35, 2.19, 2.71, 14.23, 1.69, 8.12, 23.46, 2.77, 1,
2.44, 1.27, 1.9, 6.63, 0.96, 0.87, 6.33, 1.21, 0.73, 5.9,
0.69, 1.81, 3.65, 4.46, 12, 6.21, 3.35, 1.02, 0.46, 0.21,
0.04, 6.04, 2.23, 1.42, 1.63, 1.58, 6.94, 5.35, 2.33, 1.92,
1.12, 8.98, 2.56, 0.87, 2.27, 1.08, 2.19, 10.67, 6.21, 0.38,
1.44, 0.04, 1, 1.21, 7.33, 0), row.names = c(NA,
-1432L), class = "data.frame")
Dput(Hours)
Days = c(8.5, 8.5, 8.5, 8.5, 8.5, 8, 8.5,
8.5, 8.5,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10, 10, 9, 9, 9, 9, 9, 8, 8.5, 8.5, 8.5, 8.5,
8.5, 8, 9.5, 9.5, 9.5, 9.5, 9.5, 3.5, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 3.5, 9.5, 9.5, 9.5, 9, 9.5, 8, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 8.5, 8.5, 8.5, 8.5, 8.5, 9, 9,
9, 9, 9, 10, 15, 15, 15, 15, 15, 15, 10, 10, 10, 10, 10,
10, 9, 9, 9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 6, 14, 14, 14,
14, 14, 14, 6, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 12,
12, 12, 6, 12, 12, 12, 12, 12, 12, 9, 9, 9, 9, 9, 4, 9, 9,
9, 9, 9, 8, 9.5, 9, 9, 9, 9, 3, 9.5, 9.5, 9.5, 9.5, 9.5,
3.5, 10, 10, 10, 10.5, 10, 4, 11, 11, 12, 11, 12, 10, 10,
10, 10, 10, 6, 10.5, 10.5, 10.5, 10.5, 10.5, 9, 9, 9, 9,
9, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 9.5, 9.5,
9.5, 9.5, 9.5, 9.75, 9.75, 9.75, 9.75, 9.75, 9, 9, 9, 9,
9, 9.25, 9.25, 9.25, 9.25, 9.25, 4, 10.25, 10.25, 10.25,
10.25, 10.25, 6, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 8.5, 8.5,
8.5, 8.5, 8.5, 9, 9, 9, 9, 9, 4, 8.5, 8.5, 8.5, 8.5, 8.5,
8.5, 8, 16, 16, 16, 16, 16, 12, 9, 9, 9, 9, 9, 9.5, 9.5,
9.5, 9.5, 9.5, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 8, 10.5,
10.5, 10.5, 10.5, 10.5, 10, 11.5, 11.5, 11.5, 10.5, 10.5,
4, 9, 9, 9, 9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 3, 9.5, 9.5,
9.5, 9.5, 9.5, 3, 9.5, 9.5, 9.5, 9.5, 9.5, 9, 9, 9, 9, 9,
4, 10, 10, 10, 7.5, 10, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5,
9.5, 7.5, 9.5, 2.5, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 9.5,
9.5, 9.5, 9.5, 9.5, 3, 10.5, 10.5, 10.5, 10.5, 10.5, 9, 9,
9, 9, 9, 6, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 9.5, 9.5,
9.5, 4.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9.5, 9.5, 9.5,
9.5, 9.5, 3, 9, 9, 9, 9, 9, 4, 10, 10, 10, 10, 10, 4, 9.75,
9.75, 9.75, 9.75, 9.75, 4, 9.75, 9.75, 9.75, 9.75, 9.75,
9.25, 9.25, 9.25, 4, 9.25, 9.5, 9.5, 9.5, 3.5, 9.5, 9.5,
9.5, 9.5, 9.5, 9.5, 9.75, 9.75, 9.75, 4.5, 9.75, 9, 9, 9,
9, 9, 4, 9.25, 9.25, 9.25, 9.25, 9.25, 2.5, 12, 10.5, 10.5,
10.5, 10.5, 9.75, 9.75, 9.75, 9.75, 9.75, 10, 10, 10, 10,
10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 6,
14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 12, 12, 12, 12, 12,
12, 6, 12, 12, 12, 12, 12, 12, 6, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 6, 12, 12, 12, 12, 12, 12, 9.25, 9.25, 9.25,
9.25, 9.25, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 9, 9, 9, 9,
9, 9.5, 9.5, 9.5, 9.5, 9.5, 10, 10, 10, 10, 10, 6, 10.75,
10.75, 10.75, 10.75, 10.75, 10, 10.75, 10.75, 10.75, 10.75,
10.75, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 10, 10, 10, 10, 10,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 5,
9, 9, 9, 9, 9, 5, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 9, 9, 4, 9, 9, 9, 9, 9,
9, 9, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 6, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 14.5,
14.5, 14.5, 14.5, 14.5, 14.5, 6, 12, 12, 12, 12, 12, 12,
6, 12.5, 12.5, 12.5, 12.5, 12.5, 12, 6, 14, 14, 14, 14, 14,
14, 6, 12, 12, 12, 12, 12, 12, 6, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 6, 4, 4, 4, 4, 4, 3, 9.75, 9.75, 9.75, 9.75,
9.75, 3.5, 9, 9, 9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5,
9.5, 9.5, 9.5, 9.75, 9.75, 9.75, 9.75, 9.75, 9, 9, 9, 9,
9, 9.5, 9.5, 9.5, 9.5, 9.5, 10, 10, 10, 10, 10, 4, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 11, 11,
11, 11, 11, 9.75, 9.75, 9.75, 9.75, 9.75, 10, 10, 10, 10,
10, 4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10,
10, 8, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 13.75, 14.5, 14.5,
14.5, 14.5, 14.5, 13.75, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5,
9.5, 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5, 4, 10, 10, 10, 10, 10,
4, 10, 10, 10, 10, 10, 8, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9,
9, 9, 9, 9, 8, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9.5, 9.5, 9.5,
9.5, 9.5, 3, 9, 9, 9, 9, 9, 7, 4, 9.5, 9.5, 9.5, 9.5, 9.5,
8.5, 13, 12.5, 12.5, 12.5, 12.5, 12.5, 13, 9.5, 9.5, 9.5,
9.5, 9.5, 8, 9, 9, 9, 9, 9, 8.5, 10.5, 10.5, 10.5, 10.5,
10.5, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 10.5, 10.5, 10.5, 10.5,
10.5, 8, 9, 9, 9, 9, 9, 4, 10, 10, 10, 10, 10, 8, 10, 10,
10, 10, 10, 8, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9.5, 9.5, 9.5,
9, 9.5, 4, 10, 10, 10, 10, 10, 8, 10, 11, 10, 10, 10, 10,
10, 10, 10, 10, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 10.5, 10.5, 10.5,
10.5, 10.5, 8, 10.25, 10.25, 10.25, 10.25, 10.25, 9.5, 9.5,
9.5, 9.5, 9.5, 10, 10, 10, 10, 10, 4, 9.5, 9.5, 9.5, 9, 9.5,
4, 10, 10, 10, 10, 10, 4, 10, 10, 10, 10, 10, 8.5, 9, 9,
9, 9, 9, 4, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 16,
16, 16, 16, 16, 15, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5,
6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 14.5, 14.5, 14.5,
14.5, 14.5, 14.5, 6, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5,
6, 4, 4, 4, 4, 4, 3, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9, 9, 9,
9, 9, 8.5, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 4,
9.5, 9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 4, 10.5, 10.5,
10.5, 10.5, 10.5, 8.5, 9.75, 9.75, 9.75, 9.75, 9.75, 4, 10,
10, 10, 10, 10, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 10, 10,
10, 10, 10, 8.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.25, 9.25, 9.25,
9.25, 9.25, 4, 9, 9, 9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 13,
14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 10, 10, 10, 10, 10, 13,
14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 10, 10, 10, 10, 10, 9,
10, 10, 10, 10, 10, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 9.5,
9.5, 9.5, 9.5, 9.5, 3, 9.5, 9.5, 9.5, 9.5, 9.5, 8.25, 10,
10, 10, 10, 10, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 9.5, 9.5,
9.5, 9.5, 9.5, 8.5, 9.75, 9.75, 9.75, 9.75, 9.75, 4, 9, 9,
9, 9, 9, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 6, 14.5, 14.5, 14.5,
14.5, 14.5, 14.5, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5,
6, 12, 12, 12, 12, 12, 12, 6, 14.5, 14.5, 14.5, 14.5, 14.5,
14.5, 6, 14, 14, 14, 14, 14, 14, 6, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 9, 9,
9, 9, 9, 7, 6, 9.5, 9.5, 9.5, 10.5, 10.5, 8, 8.5, 8.5, 8.5,
8.5, 8.5, 8.5, 10, 10, 10, 10, 10, 9.5, 9.5, 9.5, 9.5, 9.5,
3, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 8, 9.5, 9.25,
9.25, 9.25, 9.5, 8.5, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9,
4, 10, 10, 10, 10, 10, 8.5, 8.5, 8.5, 8.5, 8.5, 10, 10, 10,
10, 10, 9.5, 9.5, 9.5, 9.5, 9.5, 9, 9, 9, 9, 9, 8.5, 10,
10, 10, 10, 10, 8.5, 10.25, 10.25, 10.25, 10.25, 10.25, 4,
9, 9, 9, 9, 9, 5, 9.75, 9.75, 9.75, 9.75, 9.75, 4, 9, 9,
9, 9, 9, 8.5, 9, 9, 9, 9, 9, 8, 10, 10, 10, 10, 10, 9.5,
9.5, 9.5, 9.5, 9.5, 8.5, 9.75, 9.75, 9.75, 9.75, 9.75, 4,
8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 10, 10, 10, 10, 10, 9.5, 9.5,
9.5, 9.5, 9.5, 4, 10, 10, 10, 10, 10, 4, 9.5, 9.5, 9.5, 9.5,
9.5, 8, 10, 10, 10, 10, 10, 6, 12, 12, 12, 12, 12, 12, 6,
14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 12, 12, 12, 12, 12,
11, 6, 16, 16, 16, 16, 16, 15, 6, 12, 12, 12, 12, 12, 12,
6, 12, 12, 12, 12, 12, 11, 6, 16, 16, 16, 16, 16, 15, 10.25,
10.25, 10.25, 10.25, 10.25, 4, 10.5, 10.5, 9.5, 9.5, 9.5,
4, 10, 10, 10, 10, 10, 4, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9,
4, 8, 15.5, 15.5, 15.5, 15.5, 15.5, 14.5, 9.5, 9.5, 9.5,
9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 10, 10, 10, 10, 10, 9,
9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 8.5,
9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 4.5, 10,
10, 10, 10, 10, 8.5, 9, 9, 9, 9, 9, 4, 10.5, 10.5, 10.5,
10.5, 10.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8, 9, 9, 9, 9, 9, 8,
10.5, 10.5, 10.5, 12, 10.5, 10, 10.5, 10, 10.5, 10, 10, 10,
10, 10.5, 10, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 10, 10, 10, 10,
10, 10.5, 10.5, 10.5, 10.5, 10.5, 8, 9, 9, 9, 9, 9, 8, 10,
10, 10, 10, 10, 3.5, 10, 10, 10, 10, 10, 8, 10, 10, 10, 10,
10, 4, 10, 10, 10, 10, 10, 5, 9, 9, 9, 9, 9, 8.5, 9.5, 9.5,
9.5, 9.5, 9.5, 8, 10, 10, 10, 10, 10, 10.75, 10.75, 10.75,
11.75, 10.75, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 6, 14.5, 14.5,
14.5, 14.5, 14.5, 14.5, 6, 14.5, 14.5, 14.5, 14.5, 14.5,
14.5, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 12, 12, 12,
13, 13, 12, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 10.5,
10.5, 10.5, 10.5, 10.5, 8.5, 10, 10, 10, 10, 10, 4, 10.75,
9.75, 10, 9.75, 9.75, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9.5, 9.5,
9.5, 9.5, 9.5, 8.5, 10.5, 10.5, 8.5, 10.5, 10.5, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 8.5, 10, 10, 10, 10, 10,
8.5, 11.5, 11.5, 11.5, 11.5, 11.5, 10, 10, 10, 10, 10, 8.5,
10, 10, 10, 10, 10, 4, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9,
8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 10, 10, 10, 10, 10, 9, 9, 9,
8, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 12, 13, 13, 13, 13, 13, 13,
10.5, 10.5, 10, 10.5, 10.5, 9, 9, 9, 9, 9, 4, 10, 10, 10,
10, 10, 8.5, 10, 10, 10, 10, 10, 8.5, 10, 10, 10, 10, 10,
3, 10, 10, 10, 10, 10, 4, 10.5, 10.5, 10.5, 11.5, 10.5, 10,
10, 10, 10, 10, 10, 10, 10.5, 10.5, 10, 8.5, 10.5, 10.5,
10.5, 10.5, 10.5, 4, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5,
6, 12, 12, 12, 12, 12, 12, 6, 14.5, 14.5, 14.5, 14.5, 14.5,
14.5, 6, 13, 13, 13, 13, 13, 13, 6, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 9.75, 9.5, 9.75, 9.5, 9.75, 4, 11.25, 9.75, 9.75,
9.75, 9.75, 11.5, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15,
15, 10, 10, 10, 10, 10, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 10.5,
10.5, 10.5, 10.5, 10.5, 8.5, 13.5, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 10, 10, 10, 11, 10, 8.5, 8.5, 8.5, 8.5, 8.5,
8.5, 8.5, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9, 9, 9, 9, 9, 4, 10,
10, 10, 10, 10, 10.5, 10.5, 10.5, 10, 10, 8.5, 9.5, 9.5,
9.5, 9.5, 9.5, 4, 10, 10, 10, 10, 10, 8.5, 9, 9, 9, 9, 9,
4, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 7, 13, 13, 13, 13, 13, 13,
10.5, 11, 10.5, 10.5, 10.5, 4, 7, 11, 11, 11, 11, 11, 9,
9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 9, 9, 9, 9, 9, 8.5, 11, 11,
11, 11, 11, 9, 7, 13, 13, 13, 13, 13, 13, 9.5, 9.5, 9.5,
9.5, 9.5, 8.5, 10, 10, 10, 10, 10, 9.5, 9.5, 9.5, 9.5, 9.5,
4, 9, 9, 9, 9, 9, 8.5, 9, 9, 9, 9, 9, 8.5, 9, 9, 9, 9, 9,
8.5, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 9.5, 9.5, 9.5, 9.5, 9.5,
8, 10, 10, 10, 10, 10, 8.5, 9, 9, 9, 9, 9, 8.5, 9.5, 9.5,
9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 4, 6, 13, 13, 13, 13, 13,
12, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 14.5, 14.5,
14.5, 14.5, 14.5, 14.5, 10, 10, 10, 10, 10, 9, 13, 14.5,
14.5, 14.5, 14.5, 14.5, 14.5, 10.5, 10.5, 10.5, 10.5, 10.5,
9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 10, 10, 10, 10, 10, 3, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 9.75, 9.75, 9.75,
9.75, 9.75, 3, 10, 10, 10, 10, 10, 8.5, 10, 10, 10, 10, 10,
8, 9, 9, 9, 9, 9, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9, 9, 9,
9, 9, 4, 10, 10, 10, 10, 10, 4, 9, 9, 9, 9, 9, 8, 9.5, 9.5,
9.5, 9.5, 9.5, 4, 12, 12, 12, 12, 12, 12, 12, 9.5, 9.5, 9.5,
9.5, 9.5, 4, 10, 10, 10, 8, 10, 8, 10, 10, 10, 10, 10, 9,
9, 9, 9, 9, 8.5, 10.5, 10.5, 10.5, 10.5, 10.5, 4, 10.5, 10.5,
10.5, 10.5, 10.5, 10, 10, 10, 10, 10, 9.5, 9.5, 9.5, 9.5,
9.5, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5,
8, 9, 9, 9, 9, 9, 8, 6, 12, 12, 12, 12, 12, 12, 6, 14.5,
14.5, 14.5, 14.5, 14.5, 14.5, 6, 12.5, 12.5, 12.5, 12.5,
12.5, 12, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 14.5,
14.5, 14.5, 14.5, 14.5, 14.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9,
9, 9, 9, 9, 10, 10, 10, 10, 10, 3.5, 8.5, 8.5, 8.5, 8.5,
4, 9, 9, 9, 8.5, 9, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9.5, 9.5,
8.5)), row.names = c(NA, -8658L), class = "data.frame")
Any help/guidance will be grateful
Many thanks
Maybe this tidyverse solution is close to what you want. But I am no sure where Hours variable comes. You can reshape your data to wide and then merge. Here the code, as days are present in both dataframes you can directly merge like this:
library(tidyverse)
#Code
#First reshape df2
merged <- df1 %>% select(StoreNumber,Online,Pressure) %>%
left_join(
df2 %>% pivot_wider(names_from = Day,values_from=Time),
by = c('StoreNumber'='BranchNumber'))
#Replace zeroes
merged <- merged %>% replace(is.na(.),0)
Output:
StoreNumber Online Pressure MON TUE WED
1 1 0.2 50 7.5 6 8.5
2 2 0.8 20 0.0 0 0.0
3 3 1.2 10 2.0 1 2.5
Some data used:
#Data 1
df1 <- structure(list(StoreNumber = 1:3, Online = c(0.2, 0.8, 1.2),
Pressure = c(50L, 20L, 10L), MON = c(0L, 0L, 0L), TUE = c(0L,
0L, 0L), WED = c(0L, 0L, 0L), SUN = c(0L, 0L, 0L)), class = "data.frame", row.names = c(NA,
-3L))
#Data 2
df2 <- structure(list(BranchNumber = c(1L, 1L, 1L, 3L, 3L, 3L), Day = c("MON",
"TUE", "WED", "MON", "TUE", "WED"), Time = c(7.5, 6, 8.5, 2,
1, 2.5)), class = "data.frame", row.names = c(NA, -6L))
Here is my data:
test <- structure(list(date = structure(c(16436, 16437, 16438, 16439,
16440, 16441, 16442, 16443, 16444, 16445, 16446, 16447, 16448,
16449, 16450, 16451, 16452, 16453, 16454, 16455, 16456, 16457,
16458, 16459, 16460, 16461, 16462, 16463, 16464, 16465, 16466,
16467, 16468, 16469, 16470, 16471, 16472, 16473, 16474, 16475,
16476, 16477, 16478, 16479, 16480, 16481, 16482, 16483, 16484,
16485, 16486, 16487, 16488, 16489, 16490, 16491, 16492, 16493,
16494, 16495, 16496, 16497, 16498, 16499, 16500, 16501, 16502,
16503, 16504, 16505, 16506, 16507, 16508, 16509, 16510, 16511,
16512, 16513, 16514, 16515, 16516, 16517, 16518, 16519, 16520,
16521, 16522, 16523, 16524, 16525, 16526, 16527, 16528, 16529,
16530, 16531, 16532, 16533, 16534, 16535, 16536, 16537, 16538,
16539, 16540, 16541, 16542, 16543, 16544, 16545, 16546, 16547,
16548, 16549, 16550, 16551, 16552, 16553, 16554, 16555, 16556,
16557, 16558, 16559, 16560, 16561, 16562, 16563, 16564, 16565,
16566, 16567, 16568, 16569, 16570, 16571, 16572, 16573, 16574,
16575, 16576, 16577, 16578, 16579, 16580, 16581, 16582, 16583,
16584, 16585, 16586, 16587, 16588, 16589, 16590, 16591, 16592,
16593, 16594, 16595, 16596, 16597, 16598, 16599, 16600, 16601,
16602, 16603, 16604, 16605, 16606, 16607, 16608, 16609, 16610,
16611, 16612, 16613, 16614, 16615, 16616, 16617, 16618, 16619,
16620, 16621, 16622, 16623, 16624, 16625, 16626, 16627, 16628,
16629, 16630, 16631, 16632, 16633, 16634, 16635, 16636, 16637,
16638, 16639, 16640, 16641, 16642, 16643, 16644, 16645, 16646,
16647, 16648, 16649, 16650, 16651, 16652, 16653, 16654, 16655,
16656, 16657, 16658, 16659, 16660, 16661, 16662, 16663, 16664,
16665, 16666, 16667, 16668, 16669, 16670, 16671, 16672, 16673,
16674, 16675, 16676, 16677, 16678, 16679, 16680, 16681, 16682,
16683, 16684, 16685, 16686, 16687, 16688, 16689, 16690, 16691,
16692, 16693, 16694, 16695, 16696, 16697, 16698, 16699, 16700,
16701, 16702, 16703, 16704, 16705, 16706, 16707, 16708, 16709,
16710, 16711, 16712, 16713, 16714, 16715, 16716, 16717, 16718,
16719, 16720, 16721, 16722, 16723, 16724, 16725, 16726, 16727,
16728, 16729, 16730, 16731, 16732, 16733, 16734, 16735, 16736,
16737, 16738, 16739, 16740, 16741, 16742, 16743, 16744, 16745,
16746, 16747, 16748, 16749, 16750, 16751, 16752, 16753, 16754,
16755, 16756, 16757, 16758, 16759, 16760, 16761, 16762, 16763,
16764, 16765, 16766, 16767, 16768, 16769, 16770, 16771, 16772,
16773, 16774, 16775, 16776, 16777, 16778, 16779, 16780, 16781,
16782, 16783, 16784, 16785, 16786, 16787, 16788, 16789, 16790,
16791, 16792, 16793, 16794, 16795, 16796, 16797, 16798, 16799,
16800), class = "Date"), radn = c(9.66, 9.54, 8.21, 5, 5.98,
9.39, 8.54, 9.68, 6.74, 2.95, 9.24, 7.39, 10.47, 9.04, 7.1, 4.12,
6.42, 6.89, 10.96, 9.49, 11.72, 8.83, 11.48, 11.42, 11.49, 10.98,
2.87, 11.92, 8.92, 4, 12.92, 8.37, 5.73, 4.47, 8.73, 5.76, 9.34,
10.41, 6.72, 8.44, 13.34, 11.95, 12.2, 10.94, 10.5, 15.72, 14.63,
15.67, 15.91, 14.79, 14.11, 15.89, 17.07, 17.62, 17.22, 14.93,
11.17, 4.83, 8.78, 17.46, 10.35, 19.09, 19.39, 19.48, 19.12,
18.94, 19.93, 20.24, 17.47, 6.07, 19.4, 18.26, 10, 6.33, 10.67,
15.2, 21.39, 22.43, 18.02, 19.4, 18.55, 14.91, 9.15, 21.84, 22.8,
23.16, 23.43, 24.16, 22.56, 23.58, 23.45, 25.09, 25.46, 22.85,
17.05, 23.87, 12.45, 8.88, 25.7, 25.86, 17.28, 24.77, 25.08,
15.62, 27.4, 27.35, 27.71, 26.91, 27.93, 27.99, 26.42, 20.49,
27.9, 11.89, 10.38, 28.43, 28.74, 29.2, 27.62, 28.88, 28.81,
28.92, 29.07, 24.41, 29.1, 26.43, 18, 23.94, 30.68, 29.47, 18.88,
18.58, 25.79, 18.76, 12.18, 12.92, 20.18, 10.75, 14.09, 19.86,
19.47, 15.9, 12.82, 22.62, 21.23, 24.62, 29.5, 30.21, 30.12,
21.87, 25.45, 31.68, 32.18, 29.67, 17.27, 22.41, 24.28, 31.27,
30, 30.12, 21.6, 32.76, 32.27, 32.24, 32.81, 32.45, 32.66, 30.52,
30.5, 32.68, 32.85, 30.42, 32.62, 32.45, 31.29, 32.15, 25.84,
26.21, 27.22, 26.36, 30.72, 26.26, 24.34, 21.45, 18.58, 25.95,
29.09, 21.53, 21.88, 20.76, 17.56, 24.69, 22.83, 27.72, 28.07,
31.18, 30.23, 28.86, 30.61, 30.79, 30.08, 27.28, 16.81, 23.82,
30.09, 30.29, 30.45, 30.8, 31.12, 30.89, 30.19, 25.01, 24.27,
18.93, 28.27, 26.62, 27.97, 22.9, 11.1, 22.29, 24.4, 27.78, 28.17,
28.41, 26.01, 27.18, 25.08, 26.65, 27.95, 27.67, 24.39, 26.59,
26.9, 26.54, 26.02, 25.31, 26.03, 22.22, 24.29, 21.01, 19.73,
23.03, 25.38, 24.98, 24.74, 19.75, 20.24, 24.99, 21.01, 24.53,
24.3, 23.95, 23.36, 22.92, 20.66, 15.42, 6.66, 15.28, 16.1, 16.73,
22.14, 22.02, 21.59, 21.4, 21.41, 21.45, 15.48, 17.78, 19.93,
15.58, 19.22, 17.29, 8.64, 8.94, 15.46, 12.52, 17.79, 18.36,
18.28, 15.27, 13.04, 13.78, 17.88, 17.88, 17.5, 17.31, 16.84,
14.55, 15.17, 7.43, 4.34, 5.23, 12.79, 15.84, 13.32, 15.43, 11.48,
6.13, 14.64, 9.04, 5.09, 11.84, 9.86, 11.4, 4.92, 2.81, 5.76,
7.92, 9.15, 13.14, 13.14, 9.94, 9.77, 11.15, 12.45, 12.33, 11.99,
11.8, 6.92, 11.23, 6.2, 9.6, 4.89, 11.43, 11.05, 10.83, 7.44,
5.4, 6.17, 3.52, 10.71, 10.64, 10.67, 10.6, 10.17, 6.02, 6.96,
6.5, 7.43, 3.49, 2.03, 5.22, 5.02, 4.24, 4.44, 5.52, 2.72, 3.75,
2.31, 8.38, 1.88, 3.07, 2.02, 2.66, 1.67, 5.77, 7.59, 1.9, 1.5,
9.72, 2.66, 2.39, 1.67, 2.38, 9.88), maxt = c(-4.4, -1.9, 0.8,
4.8, 6.8, 11, 13, 12.6, 11.4, 7, 5.8, 10, 7.2, 6.5, 5.9, 5.5,
10.4, 12, 15.6, 11.2, 7.1, 6.3, 6.5, 9.4, 12.8, 14.6, 14.3, 7.8,
11.9, 9.6, 4.5, 10.8, 13.2, 11.4, 14, 14.8, 14.9, 16.3, 17.2,
15.4, 13.3, 12.4, 15.1, 17.6, 19.6, 19.8, 15.1, 12.8, 15.9, 18.7,
18, 13.1, 10.6, 6, 7.6, 12.7, 14, 9.2, 8.3, 7.1, 9.5, 10, 6,
10.1, 15.5, 18.4, 19.9, 19.6, 19.9, 21.5, 13.9, 17, 20.5, 20.6,
22.7, 18.4, 18.5, 16, 19.9, 22.2, 19.1, 19.3, 12.6, 11.7, 17.1,
22.2, 26.5, 19.7, 22.9, 26.3, 20.7, 12.2, 12.4, 16.3, 17.4, 12.7,
12.7, 13, 11.4, 16.4, 20.6, 16.6, 18.4, 24.4, 11.7, 11.8, 18.6,
23, 21.9, 23.3, 24.6, 26, 22.5, 21.6, 13.2, 11.9, 14.8, 21.2,
25.8, 25.5, 22.6, 26.7, 27.6, 26.9, 27.2, 24.2, 18.6, 14.1, 20.5,
21.6, 24.2, 22.6, 20.9, 19.6, 16.9, 14.8, 17.1, 20.6, 18.3, 16.9,
20.2, 21.2, 19.6, 19.2, 22.6, 24, 23.9, 25.6, 27.1, 29.3, 30.2,
31.6, 26.4, 24.7, 25.2, 21, 25.9, 26.4, 30.7, 33.4, 34.7, 29,
30.5, 32.3, 31.9, 32.6, 32.6, 32.7, 33.6, 34, 31.6, 32.4, 31.4,
31.5, 33.7, 35.9, 37.1, 38.8, 39.2, 38.9, 37.8, 38.4, 38.3, 38.6,
37.2, 35.7, 27.9, 33.4, 32.7, 27.5, 29.2, 26.3, 26.9, 28, 29.1,
31.1, 32, 33.1, 29.4, 29.2, 32.3, 34, 33, 29, 29.3, 30.8, 31.5,
30.4, 24.9, 28.5, 33.6, 36.3, 37.7, 38.2, 34.5, 33.2, 33.9, 29.2,
32.3, 25.4, 28.8, 32.4, 32.9, 34.9, 34.6, 36.2, 34.5, 32, 34.1,
33.7, 33.3, 34.8, 34.5, 32.7, 32.3, 35.7, 35.3, 35, 34.2, 33.5,
33.9, 31.4, 27.6, 30.9, 32.2, 30.5, 25.9, 23.5, 19.6, 24.1, 28.1,
30.8, 33.2, 34.8, 35.8, 35.4, 33.5, 27.7, 21.7, 19.4, 20.1, 23.7,
28.5, 31.5, 31.6, 31, 29.3, 31.2, 32.6, 30.5, 28.6, 29.8, 30.9,
26.8, 21.1, 21.8, 20.4, 22.5, 24.9, 26.7, 27.1, 28, 30.7, 29.6,
25.5, 29.3, 30.4, 30.8, 30.5, 29, 22, 18, 13.1, 16, 19, 19.1,
19.3, 20.1, 20, 20.4, 18.6, 15.2, 13.7, 17.1, 22.3, 18.1, 6.3,
6, 5.7, 7.1, 10.3, 11.1, 14.2, 8, 7.1, 8.9, 10.7, 12.3, 14.8,
10.8, 3.2, 7.6, 12.6, 14.4, 9.6, 10.6, 11.7, 12.3, 13.4, 1.3,
-0.9, -0.2, 0.6, 2.5, 4, 5.4, 7.3, 13, 8, 6.7, 11.5, 13.2, 14.2,
14.9, 12.3, 5.5, 6.1, 11.1, 0.3, 0.5, 2, 2.8, 7, 4.9, 2.4, 7.3,
6.2, 2.9, 0.5, -1.2, -2.5, -4, -2.7, -1.1, -3), mint = c(-15.9,
-16.5, -14.4, -11.2, -5.7, -2.4, -2.5, -3.2, -4.3, -4.6, -1.5,
-1, -0.9, -6.3, -7, -5.7, -1.2, -0.9, 0.3, -2.7, -5.9, -10.1,
-8.7, -7.3, -5.7, -3.5, -1.2, -0.4, -0.9, -0.7, -4.3, -4.3, -2.8,
1, 2.7, 3.1, 5.8, 6.2, 3.8, 2.2, -0.7, -1.5, -0.9, -0.3, 1, 1,
-1.6, -3.8, -3.9, -1.9, -0.6, -0.8, -3.8, -7, -8.8, -7, -2.2,
-0.3, -1.1, -2.9, -5.1, -5.2, -9.2, -9.7, -6.9, -4.2, -3.1, -3.5,
-3.8, -2.3, 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, 1.37, 0,
2.3, 1.74, 3.2, 1.72, 3.53, 2, 1.08, 0.46, 0.38, 0.3, 0, 0, 0,
0.47, 0, 0, 0.56, 4.86, 9.66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.86,
0, 0, 0, 0, 2.44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0.55, 0.83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16.08,
0.93, 0.01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.24, 4.25, 14.52,
13.45, 0, 0, 0, 0, 0, 0, 0, 0, 1.2, 1.23, 0, 0, 4.15, 11.05,
2.29, 0, 0, 0, 0, 0.77, 3.04, 0, 0, 0, 0, 0, 0.88, 0, 0, 0, 0,
0, 0, 0, 0, 0.94, 0, 0, 0, 0, 0, 0, 0.02, 0, 0, 0, 0, 0, 0, 0,
0.66, 1.85, 0.95, 0.61, 3.89, 0, 0, 1.23, 4.81, 0, 1.96, 1.67,
6.94, 9.65, 0, 1.99, 0, 0, 2.24, 2.67, 0.16, 0.52), evap = c(8.48,
8.48, 8.48, 8.48, 8.48, 8.48, 8.48, 8.31, 8.31, 8.31, 8.31, 8.31,
8.31, 8.31, 8.09, 8.09, 8.09, 8.09, 8.09, 8.09, 8.09, 7.86, 7.86,
7.86, 7.86, 7.86, 7.86, 7.86, 7.62, 7.62, 7.62, 7.62, 7.62, 7.62,
7.62, 7.39, 7.39, 7.39, 7.39, 7.39, 7.39, 7.39, 7.16, 7.16, 7.16,
7.16, 7.16, 7.16, 7.16, 6.93, 6.93, 6.93, 6.93, 6.93, 6.93, 6.93,
6.71, 6.71, 6.71, 6.71, 6.71, 6.71, 6.71, 6.48, 6.48, 6.48, 6.48,
6.48, 6.48, 6.48, 6.23, 6.23, 6.23, 6.23, 6.23, 6.23, 6.23, 5.96,
5.96, 5.96, 5.96, 5.96, 5.96, 5.96, 5.66, 5.66, 5.66, 5.66, 5.66,
5.66, 5.66, 5.32, 5.32, 5.32, 5.32, 5.32, 5.32, 5.32, 4.95, 4.95,
4.95, 4.95, 4.95, 4.95, 4.95, 4.56, 4.56, 4.56, 4.56, 4.56, 4.56,
4.56, 4.15, 4.15, 4.15, 4.15, 4.15, 4.15, 4.15, 3.75, 3.75, 3.75,
3.75, 3.75, 3.75, 3.75, 3.38, 3.38, 3.38, 3.38, 3.38, 3.38, 3.38,
3.05, 3.05, 3.05, 3.05, 3.05, 3.05, 3.05, 2.78, 2.78, 2.78, 2.78,
2.78, 2.78, 2.78, 2.58, 2.58, 2.58, 2.58, 2.58, 2.58, 2.58, 2.45,
2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.37, 2.37, 2.37, 2.37, 2.37,
2.37, 2.37, 2.35, 2.35, 2.35, 2.35, 2.35, 2.35, 2.35, 2.38, 2.38,
2.38, 2.38, 2.38, 2.38, 2.38, 2.46, 2.46, 2.46, 2.46, 2.46, 2.46,
2.46, 2.57, 2.57, 2.57, 2.57, 2.57, 2.57, 2.57, 2.72, 2.72, 2.72,
2.72, 2.72, 2.72, 2.72, 2.9, 2.9, 2.9, 2.9, 2.9, 2.9, 2.9, 3.1,
3.1, 3.1, 3.1, 3.1, 3.1, 3.1, 3.33, 3.33, 3.33, 3.33, 3.33, 3.33,
3.33, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.83, 3.83, 3.83,
3.83, 3.83, 3.83, 3.83, 4.13, 4.13, 4.13, 4.13, 4.13, 4.13, 4.13,
4.47, 4.47, 4.47, 4.47, 4.47, 4.47, 4.47, 4.85, 4.85, 4.85, 4.85,
4.85, 4.85, 4.85, 5.26, 5.26, 5.26, 5.26, 5.26, 5.26, 5.26, 5.67,
5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 6.08, 6.08, 6.08, 6.08, 6.08,
6.08, 6.08, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.79, 6.79,
6.79, 6.79, 6.79, 6.79, 6.79, 7.09, 7.09, 7.09, 7.09, 7.09, 7.09,
7.09, 7.35, 7.35, 7.35, 7.35, 7.35, 7.35, 7.35, 7.6, 7.6, 7.6,
7.6, 7.6, 7.6, 7.6, 7.84, 7.84, 7.84, 7.84, 7.84, 7.84, 7.84,
8.07, 8.07, 8.07, 8.07, 8.07, 8.07, 8.07, 8.28, 8.28, 8.28, 8.28,
8.28, 8.28, 8.28, 8.46, 8.46, 8.46, 8.46, 8.46, 8.46, 8.46, 8.58,
8.58, 8.58, 8.58, 8.58, 8.58, 8.58, 8.63, 8.63, 8.63, 8.63, 8.63,
8.63, 8.63, 8.6, 8.6, 8.6, 8.6, 8.6, 8.6, 8.6, 8.6), index = 8767:9131), .Names = c("date",
"radn", "maxt", "mint", "rain", "evap", "index"), na.action = structure(1L, .Names = "1", class = "omit"), row.names = 8768:9132, class = "data.frame")
I am trying to optimize a function to it to simulate some data. I have done this in the past with other datasets with success, but with this data optim is converging but visually the fit is terrible. I do a much better job using guess and check. Here I am looking at minimum temperature. I have many years of data, but in the interest of space I only included 1 year.
Here is my optimization code:
TMIN <- function(a,b,x){a*sin(b*x)}
plot(h$mint~h$index,type='l')
curve(TMIN(x, a=20, b=.017),add=TRUE, col="red")
normTMIN<-function(params,k){
a=params[1]
b=params[2]
c=params[3]
Mean<-mean(a*sin(b*k))
-sum(dnorm(k,mean=Mean,sd=c,log=TRUE)) #shape= Mean(a,b)/scale
}
optTMIN <- optim(par=c(a=60,b=.017,c=1),k=test$mint,fn=normTMIN) #par doesn't equal params
optTMIN
curve(TMIN(optTMIN$par[1],optTMIN$par[2],x), add=TRUE,col="blue")
I can't figure out why optim is going so terribly wrong. Thanks in advance.
Do you want to do something like the following (find list square estimate):
head(test)
TMIN <- function(a,b,x){a*sin(b*x)}
plot(test$mint~test$index,type='l')
curve(TMIN(x, a=20, b=.017),add=TRUE, col="red")
normTMIN<-function(params,k,x){
a=params[1]
b=params[2]
sum((k - TMIN(a,b,x))^2)
}
optTMIN <- optim(par=c(a=1,b=0.001),k=test$mint,x=test$index,fn=normTMIN, control=list(trace = TRUE)) #par doesn't equal params
optTMIN
curve(TMIN(optTMIN$par[1],optTMIN$par[2],x), add=TRUE,col="blue")
#$par
# a b
#10.97271664 0.01349994