Convert split data into dataframe in r - r

Please, can anyone explain to me how to put this split data (Fibre) into a dataframe in r. So that I can have two columns: Group and Observation.
Fibre
[[1]]
12.5, 5, 4.5, 6, 10.2, 9.6, 15.5, 12.2, 13, 17.5, 13, 14
[[2]]
11.5, 7, 4.5, 8, 13.2, 19.6, 13.5, 15.2, 13.5, 20,17
[[3]]
10.5, 6, 8.5, 8, 11.2, 14.6, 19.5, 15.9, 14.5, 21,12,15,17,18
[[4]]
9.5, 16, 9.5, 8.5, 13.5, 12.6, 11.5, 16.7, 14, 19.5
I used:
NewData <- as.data.frame(Fibre)

Related

Using a Unique Identifier, Match Row Values with Column Names in R

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, 8.5, 8.5, 8, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 8,
9, 9, 9, 9, 9, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9,
9, 8.5, 10, 13, 13, 13, 13, 13, 10, 9, 9, 9, 9, 9, 4, 9.25,
9.25, 9.25, 9.25, 9.25, 3, 8.75, 8.75, 8.75, 8.75, 8.75,
8.25, 8.5, 8.5, 8.5, 8.5, 9, 4, 4, 9, 9, 9, 9, 9, 8, 8.75,
8.75, 8.75, 8.75, 8.75, 4.25, 9, 9, 9, 9, 9, 8.5, 9, 9, 9,
13, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 9.5, 9.5,
9.5, 9.5, 9.5, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 4, 9, 9, 9,
9, 9, 9, 9, 8.5, 8.5, 9, 3, 9, 9, 9, 9, 9, 10, 15, 15, 15,
15, 15, 15, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5,
8.5, 7, 10, 15, 15, 15, 15, 15, 15, 11, 11, 11, 11, 11, 9.5,
9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 8.5, 9, 9, 9, 9, 9,
9, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5,
8, 9, 9, 9, 9, 9, 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,
12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 9, 9, 9, 9, 9, 10.5,
10.5, 10.5, 10.5, 10.5, 7.5, 6, 11.5, 11.5, 11.5, 11.5, 11.5,
11.5, 12, 12, 12, 12, 12, 5, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 3, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 5,
10, 10, 10, 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, 9.5, 9.5, 9.5, 9.5, 8, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9.5,
9.5, 9.5, 9.5, 9.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 9,
9, 9, 9, 9, 8.5, 5, 14, 14, 14, 14, 14, 12, 10.5, 10.5, 10.5,
10.5, 10.5, 4, 10.5, 10.5, 10.5, 10.5, 10.5, 9, 9, 9, 9,
9, 8.5, 9, 9, 9, 9, 9, 8.5, 10, 10, 10, 10, 10, 3, 9, 9,
9, 9, 9, 8, 9, 9, 11, 11, 11, 8, 9, 9, 9, 9, 9, 8.5, 9, 9,
9, 9, 9, 4, 9, 9, 9, 9, 9, 8.5, 9, 9, 9, 9, 9, 4, 9, 9, 9,
9, 9, 9, 5, 9, 9, 12, 12, 12, 8.5, 9, 9, 9, 9, 9, 4, 8.5,
8.5, 8.5, 8.5, 8.5, 4, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5,
8.5, 8.5, 8.5, 8.5, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 3, 11,
11, 11, 11, 11, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 5, 9, 9, 9, 9,
9, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 4, 8.5, 8.5, 8.5, 8.5, 8.5,
8, 8.5, 8.5, 8.5, 8.5, 8.5, 7.5, 9.5, 9.5, 9.5, 9.5, 9.5,
4, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5,
4, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 9, 9, 9, 9, 9, 8.5, 6, 12.5,
12.5, 12.5, 12.5, 12.5, 11.5, 6, 11.5, 11.5, 11.5, 11.5,
11.5, 12, 6, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 13, 13,
12, 6, 12, 12, 12, 12, 12, 12, 6, 15.5, 15.5, 15.5, 15.5,
15.5, 15.5, 9.5, 9.5, 9.5, 9.5, 9.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))

R cut function: how to cut data which can include the right lowest and highest boundaries

I am a beginner in R. I used cut function in R to bin my data. My data starts from 0 but after cutting the lower boundary has a negative result and I have no idea why this happened.
My code is:
cancer_rtcl$cancer_rate_cut=cut(cancer_rtcl$rate,6)
The statistical summary of my data is:
> summary(cancer_rtcl$rate)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.0 13.3 16.5 16.4 18.8 63.5
> dput(cancer_rtcl$rate)
c(63.5, 41.5, 36, 33.9, 29.7, 27.2, 27.2, 26, 25.9, 25.9, 25.3,
25.1, 24.6, 24.3, 23.6, 23.3, 22.8, 22.7, 22.5, 22.4, 22.3, 22.3,
21.9, 21.9, 21.7, 21.6, 21.5, 21.4, 21.3, 21.2, 21.2, 20.9, 20.8,
20.7, 20.5, 20.5, 20.3, 20.2, 20, 19.7, 19.7, 19.6, 19.6, 19.5,
19.4, 19.1, 19, 19, 19, 18.9, 18.9, 18.8, 18.8, 18.8, 18.8, 18.8,
18.7, 18.5, 18.5, 18.5, 18.4, 18.3, 18.3, 18.2, 18.2, 18.2, 18.1,
18.1, 18, 17.9, 17.9, 17.9, 17.8, 17.8, 17.8, 17.7, 17.7, 17.6,
17.6, 17.6, 17.5, 17.4, 17.4, 17.3, 17.3, 17.3, 17.3, 17.3, 17.2,
17.2, 17.1, 17.1, 17.1, 17, 17, 16.9, 16.9, 16.9, 16.8, 16.8,
16.7, 16.6, 16.6, 16.6, 16.5, 16.5, 16.5, 16.5, 16.5, 16.4, 16.4,
16.4, 16.4, 16.2, 16.1, 16, 16, 16, 16, 15.9, 15.9, 15.8, 15.8,
15.7, 15.7, 15.7, 15.7, 15.6, 15.6, 15.6, 15.6, 15.6, 15.5, 15.4,
15.4, 15.4, 15.3, 15.3, 15.3, 15.3, 15.2, 15.1, 15.1, 15, 15,
14.8, 14.6, 14.6, 14.4, 14.2, 14.2, 14.1, 14.1, 14.1, 14.1, 14,
13.9, 13.8, 13.7, 13.6, 13.6, 13.6, 13.3, 13.2, 13.2, 13.1, 13.1,
13, 12.9, 12.9, 12.7, 12.6, 12.5, 12.4, 12.3, 12.3, 12.2, 12,
11.9, 11.8, 11.6, 11.6, 11.4, 11.4, 11.3, 11, 10.8, 10.8, 10.7,
10.6, 10.5, 10.2, 9.9, 9.8, 9.7, 9.7, 9.6, 9.6, 9.5, 9.3, 9.2,
9.2, 9, 9, 8, 7.9, 7.3, 7.1, 7, 6.9, 6.3, 4.6, 0, 0, 0, 0, 0)
But the cutting result is:
6 Levels: (-0.0635,10.6] (10.6,21.2] (21.2,31.8] (31.8,42.3] ... (52.9,63.6]
As you can see, the lowest boundary is a negative result, which is not ideal because I need to make a map based on the binned data.
I also tried another type of coding:
cancer_rtcl$rate_cut=cut(cancer_rtcl$rate,c(5,10,15,20,25))
But in this way, I lost the data larger than 25.
Can anyone help to figure out how to bin the data and get the exact lowest and highest boundaries?
Thanks!
Does this work to capture data larger than 25? cancer_rtcl$rate_cut1=cut(cancer_rtcl$rate,c(5,10,15,20,25,Inf))

Seasonal adjustment package (Census Bureau) in R only adjusting half the data

I've managed to get the library(seasonal) package to run perfectly on half my data (columns 2 and 8) but it refuses to seasonally adjust the other half. I'm really confused as the code runs fine and no error shows up, so I'm wondering if this is a feature of my data (I'm new to time-series) or are there hidden errors in my code?
head(x)
Date European Maori Pacific Peoples Asian MELAA Other Ethnicity Total
1 2004-09-30 7.9 17.9 14.8 15.4 13.4 14.1 9.7
2 2004-12-31 7.9 18.6 13.3 20.9 14.3 14.9 9.9
3 2005-03-31 7.8 17.8 14.6 21.1 12.6 16.1 9.8
4 2005-06-30 7.6 18.1 11.9 20.4 12.6 13.7 9.4
5 2005-09-30 7.1 17.4 10.5 16.1 9.4 19.2 9.0
6 2005-12-31 7.6 15.9 9.8 16.6 11.1 12.0 9.3
Code as follows:
*Note the seasonal adjustment runs smoothly in sub1 and sub2. No seasonal adjustment occurs in sub3 and sub4
library(tidyverse)
library(seasonal)
x <- read.csv("HLF524501_20191112_083700_50.csv", header = TRUE, check.names = FALSE, stringsAsFactors = FALSE)
x <- x %>%
mutate(Date = ifelse(substring(Date, 5, nchar(x)) == "Q3", paste(substring(Date, 0, 4), "09-30", sep = "-"),
ifelse(substring(Date, 5, nchar(x)) == "Q4", paste(substring(Date, 0, 4), "12-31", sep = "-"),
ifelse(substring(Date, 5, nchar(x)) == "Q1", paste(substring(Date, 0, 4), "03-31", sep = "-"),
paste(substring(Date, 0, 4), "06-30", sep = "-")))))
x$Date <- as.Date(x$Date)
sub1 <- x[,c(1,8)]
season0<-ts(sub1[,-1],frequency=4,start=c(2004,3))
sea1 <- seas(season0)
plot(sea1)
sub2 <- x[,c(1,2)]
season0<-ts(sub2[,-1],frequency=4,start=c(2004,3))
sea2 <- seas(season0)
plot(sea2)
sub3 <- x[,c(1,3)]
season0<-ts(sub3[,-1],frequency=4,start=c(2004,3))
sea3 <- seas(season0)
plot(sea3)
sub4 <- x[,c(1,4)]
season0<-ts(sub4[,-1],frequency=4,start=c(2004,3))
sea4 <- seas(season0)
plot(sea4)
Data as follows:
dput(x)
structure(list(Date = c("2004-09-30", "2004-12-31", "2005-03-31",
"2005-06-30", "2005-09-30", "2005-12-31", "2006-03-31", "2006-06-30",
"2006-09-30", "2006-12-31", "2007-03-31", "2007-06-30", "2007-09-30",
"2007-12-31", "2008-03-31", "2008-06-30", "2008-09-30", "2008-12-31",
"2009-03-31", "2009-06-30", "2009-09-30", "2009-12-31", "2010-03-31",
"2010-06-30", "2010-09-30", "2010-12-31", "2011-03-31", "2011-06-30",
"2011-09-30", "2011-12-31", "2012-03-31", "2012-06-30", "2012-09-30",
"2012-12-31", "2013-03-31", "2013-06-30", "2013-09-30", "2013-12-31",
"2014-03-31", "2014-06-30", "2014-09-30", "2014-12-31", "2015-03-31",
"2015-06-30", "2015-09-30", "2015-12-31", "2016-03-31", "2016-06-30",
"2016-09-30", "2016-12-31", "2017-03-31", "2017-06-30", "2017-09-30",
"2017-12-31", "2018-03-31", "2018-06-30", "2018-09-30", "2018-12-31",
"2019-03-31", "2019-06-30", "2019-09-30"), European = c(7.9,
7.9, 7.8, 7.6, 7.1, 7.6, 7.7, 6.7, 7.2, 8.5, 8.1, 7.8, 7.2, 7.7,
9, 8.1, 8.9, 9.6, 10.8, 11.5, 12.1, 12.5, 11.4, 11.3, 10.9, 11.4,
11.8, 11.7, 10.9, 11, 11.6, 11.8, 12.6, 12.4, 11.1, 10.7, 11.2,
12.2, 11.2, 10.8, 10.3, 11.7, 11.3, 10.9, 11, 10.7, 11.4, 10.9,
10.4, 11.1, 10.6, 10.1, 10, 11.1, 11, 10.4, 9.5, 11.4, 10.2,
9.5, 8.7), Maori = c(17.9, 18.6, 17.8, 18.1, 17.4, 15.9, 17.3,
16.1, 15.6, 18.1, 19.3, 17, 16.8, 15.9, 18.9, 16.2, 17.5, 18.9,
21.7, 22.4, 24.9, 26.3, 25, 25.5, 25.6, 25.1, 25.8, 25.5, 25.1,
24.5, 25, 25, 28.1, 28.4, 24, 24.7, 24.8, 25.7, 24.5, 22.9, 23.1,
25.1, 24.4, 24, 25.1, 23.5, 25.2, 22.8, 22.9, 23.1, 22.3, 21.4,
20.6, 21.7, 20.9, 20.3, 19, 20.9, 19.3, 17.6, 17.6), `Pacific Peoples` = c(14.8,
13.3, 14.6, 11.9, 10.5, 9.8, 15, 12.3, 12.3, 12.6, 11.6, 15,
9.5, 12.8, 17.6, 13.2, 15.6, 16.1, 21.3, 23.4, 25.1, 25.8, 24.4,
25.8, 26.1, 24.8, 24.2, 25.1, 25.2, 24.2, 27.6, 27.8, 29.6, 29.2,
27.7, 27.7, 27.2, 26.2, 24.8, 21.6, 22.4, 22.9, 23.7, 20.8, 23.9,
21.7, 21.8, 18.8, 18.7, 19.8, 19.9, 18.9, 18.4, 18.5, 16.9, 17.4,
14.8, 20.4, 18, 15.5, 14.1), Asian = c(15.4, 20.9, 21.1, 20.4,
16.1, 16.6, 11.1, 12.5, 8.9, 19.6, 17.3, 14.6, 15.5, 13.3, 13.9,
14.6, 13.4, 15.2, 16, 17, 20.6, 19.4, 18.2, 18.7, 17.9, 17.8,
18.2, 15.2, 15.3, 19, 18.4, 18.3, 18.5, 17.8, 14, 14.7, 14.4,
14.5, 14.9, 14.9, 13, 13.7, 15.6, 14.9, 13.7, 14.5, 17.5, 14.6,
13.4, 12.5, 13.1, 11.3, 11.1, 13.1, 11.9, 11.1, 11.1, 12.5, 11.1,
10.5, 9.5), MELAA = c(13.4, 14.3, 12.6, 12.6, 9.4, 11.1, 18.6,
7, 13.7, 15.4, 19.7, 20.5, 12.1, 15.9, 25.8, 21.7, 25.6, 26.4,
26.5, 26.9, 19.1, 28.5, 23, 21.4, 24.2, 14.5, 19.8, 25, 27.1,
14.2, 23.7, 22.4, 23.8, 21.8, 18.3, 14.5, 21.7, 20.7, 25.5, 21.4,
20.9, 26.2, 21.9, 25.9, 19.9, 18.7, 21.7, 19, 15.8, 23.9, 17.4,
18.3, 17, 20.3, 17.5, 17.9, 10.9, 16.1, 14.9, 22.6, 13.5), `Other Ethnicity` = c(14.1,
14.9, 16.1, 13.7, 19.2, 12, 9.8, 13.4, 10.1, 16.6, 10, 16.1,
18.5, 9.2, 9.2, 13, 8.2, 9.8, 6.7, 8.6, 10.2, 9.1, 12.6, 10.6,
8.8, 10.6, 11.1, 12.5, 12, 13.7, 15, 16.8, 12.2, 12.7, 7.9, 10.8,
12.5, 13.2, 12.1, 12.4, 8.5, 9.5, 13.1, 12.6, 10.2, 7.8, 9.4,
11.8, 11.9, 14.2, 13, 13.4, 12.3, 12.6, 13.4, 11.6, 13.7, 11.4,
11.2, 13.6, 9.3), Total = c(9.7, 9.9, 9.8, 9.4, 9, 9.3, 9.4,
8.5, 8.6, 10.3, 10.3, 9.7, 8.8, 9.2, 10.8, 9.8, 10.3, 11.2, 12.6,
13.4, 14.6, 14.9, 13.9, 13.8, 13.7, 13.9, 14.3, 13.8, 13.4, 13.6,
14.3, 14.4, 15.3, 14.9, 13.2, 13, 13.5, 14.4, 13.4, 12.9, 12.3,
13.7, 13.8, 13.2, 13.2, 12.8, 13.8, 12.7, 12.2, 12.8, 12.5, 11.6,
11.7, 12.6, 12.1, 11.7, 10.9, 12.8, 11.5, 10.8, 9.9)), class = "data.frame", row.names = c(NA,
-61L))
Would really appreciate any help :)
Thanks!
The seas function doesn't include seasonality if it doesn't detect seasonality in the data. This is based on QS statistics, which is discussed in detail here: https://stats.stackexchange.com/questions/148573/the-results-and-specifics-from-the-qs-function-in-r
You can use summary(sea1) and qs(sea1) vs. summary(sea3) and qs(sea3) to see ARIMA modeling details and the tests for seasonality on your data. More broadly, would recommend using summary on all 4 of your models to see the modeling details for each part of your data.

How to set to 0 all values that appeares less than k times in variables within nested df

library(tidyverse)
ex <- structure(list(group = c("Group A", "Group B", "Group C"), data = list(
structure(list(a = c(25.1, 15.1, 28.7, 29.7, 5.3, 3.4, 5.3,
10.1, 2.4, 18, 4.7, 22.1, 9.5, 3.1, 26.5, 5.1, 24, 22.5,
19.4, 22.9, 24.5, 18.2, 7.9, 5.3, 24.7), b = c(95.1, 51,
100, 94.1, 47.3, 0, 50.7, 45.8, 40.7, 49.4, 51.9, 76.4, 26.7,
19.8, 37.4, 59.4, 59.1, 60.2, 26.1, 2.8, 100, 40.7, 56.4,
42.5, 0), c = c(39.9, 42.7, 16.3, 11.1, 56.9, 17.8, 62, 28.1,
43, 44.8, 54.8, 8.7, 5.5, 40.2, 7.7, 60.7, 24.8, 7.5, 3.5,
16.9, 31.6, 45.8, 76.7, 58.6, 15.8), d = c(-2.39999999999999,
28.6, -4.59999999999999, -1.39999999999999, 10.3, 3.1, 23.4,
-43, -36.3, 32.4, 33.1, 9.8, 1.5, -17.6, 16.6, 20.9, 7.8,
-1.7, -23.3, 0, -15, 59.3, -40.2, 46.9, 4.7)), .Names = c("a",
"b", "c", "d"), row.names = c(NA, -25L), class = c("tbl_df",
"tbl", "data.frame")), structure(list(a = c(5, 4.7, 30.3,
14.3, 31.6, 6, 4.9, 23.3, 26.9, 16.9, 27.2, 23.8, 19.9, 28.6,
9.9, 17.4, 14.3, 12.5, 30.4, 30.3, 30, 6, 18, 23.7, 5.1),
b = c(48.9, 41.3, 20.1, 63.7, 85.1, 30.3, 52.8, 49.7,
27.1, 51.6, 21.8, 52.4, 52.5, 59.6, 13.7, 53.1, 69, 66.9,
23.4, 35.4, 45.8, 23.7, 62.9, 90.3, 59.6), c = c(37.4,
18.5, 64.6, 13.5, 7.8, 6.8, 12.7, 8.5, 7.8, 5.4, 14.1,
20.5, 10.9, 10.5, 7.5, 14.7, 6.9, 0.699999999999999,
4.7, 1.9, 11.9, 0.9, 7.2, 9.2, 42.2), d = c(4.9, -3.7,
13.5, 21.9, -2.69999999999999, 6.6, 0.5, -12.3, 38.7,
-25.8, -18, 28.4, 38.3, -3.6, 39.4, 19, 23.4, -38.7,
17, 36.3, -31.7, -9.3, -10.5, 9.7, -10.6)), .Names = c("a",
"b", "c", "d"), row.names = c(NA, -25L), class = c("tbl_df",
"tbl", "data.frame")), structure(list(a = c(29.9, 12.8, 23.9,
26.2, 27.5, 32.6, 33.2, 24.8, 29, 22.6, 4.7, 25.6, 4.7, 13.1,
25.9, 14.5, 23.5, 26.6, 12.8, 24.1, 9.1, 31.9, 24.8, 4.6,
17.9), b = c(63.7, 23.3, 71.2, 46.7, 30.6, 49.3, 14.6, 68.4,
27.9, 49.1, 60.5, 26.4, 56.9, 55.4, 37.9, 40.7, 32.7, 68.5,
42.7, 27.9, 67.5, 43.4, 76.6, 53.3, 26.8), c = c(1.6, 32,
18.6, 14, 0.5, 7.2, 27.3, 8.9, 11, 15.5, 16.7, 16.4, 63.1,
14.7, 6.8, 9, 3.1, 11.7, 11, 11.5, 10.6, 14.9, 7.1, 13.2,
5.1), d = c(-35.4, 21, 12, 1.8, 37.6, 9.2, 17.6, 0, -19.4,
32.6, -32, -3.6, 7.2, -25.7, 9.1, -8, 35.8, 24.8, -13.9,
-21.7, -28.7, 0.200000000000003, -16.9, -26.5, 26.2)), .Names = c("a",
"b", "c", "d"), row.names = c(NA, -25L), class = c("tbl_df",
"tbl", "data.frame"))), h_candidates = list(structure(c(0.17320508075689, 2.37782856461527, 2.94890646051978, 3.35205778704499, 3.66771041547043, 3.95224618679369), .Names = c("0%", "0.01%", "0.02%", "0.03%", "0.04%", "0.05%")), structure(c(0.316227766016836, 2.63452963884554, 3.2327619513522, 3.63593179253957, 3.97743636027027, 4.22137418384109), .Names = c("0%", "0.01%", "0.02%", "0.03%", "0.04%", "0.05%")), structure(c(0.316227766016837, 2.7258026340878, 3.24807635378234, 3.62353418639869, 3.92683078321437, 4.17731971484109), .Names = c("0%", "0.01%", "0.02%", "0.03%", "0.04%", "0.05%"))), assignment = list(
structure(list(`0%` = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25),
`0.01%` = c(1, 2, 3, 3, 4, 5, 4, 6, 7, 8, 9, 10, 11,
12, 13, 4, 14, 15, 16, 17, 18, 19, 20, 21, 17), `0.02%` = c(1,
2, 3, 3, 4, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 4, 14,
15, 16, 17, 18, 19, 20, 21, 17), `0.03%` = c(1, 2, 3,
3, 4, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 4, 10, 14, 15,
16, 17, 18, 19, 9, 16), `0.04%` = c(1, 2, 3, 4, 5, 6,
5, 7, 8, 9, 10, 11, 12, 13, 14, 5, 11, 15, 16, 17, 18,
19, 20, 10, 17)), .Names = c("0%", "0.01%", "0.02%",
"0.03%", "0.04%"), row.names = c(NA, -25L), class = c("tbl_df",
"tbl", "data.frame")), structure(list(`0%` = c(1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25), `0.01%` = c(1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16, 4, 17, 18, 19, 20, 21, 22,
23, 24), `0.02%` = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 13, 4, 16, 17, 9, 18, 19, 14, 20, 21), `0.03%` = c(1,
2, 3, 4, 5, 6, 2, 7, 8, 9, 10, 11, 12, 13, 14, 12, 4, 15,
6, 8, 16, 17, 13, 18, 19), `0.04%` = c(1, 2, 3, 4, 5, 6,
2, 7, 8, 9, 10, 11, 12, 13, 14, 12, 4, 15, 6, 8, 7, 16, 13,
17, 1)), .Names = c("0%", "0.01%", "0.02%", "0.03%", "0.04%"
), row.names = c(NA, -25L), class = c("tbl_df", "tbl", "data.frame"
)), structure(list(`0%` = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
), `0.01%` = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 12, 15, 16, 17, 15, 18, 19, 4, 20, 21, 22), `0.02%` = c(1,
2, 3, 4, 5, 6, 7, 8, 9, 5, 10, 11, 12, 13, 11, 14, 5, 15,
14, 16, 17, 18, 8, 19, 20), `0.03%` = c(1, 2, 3, 4, 5, 6,
7, 3, 8, 9, 10, 11, 12, 10, 11, 13, 5, 14, 13, 8, 10, 4,
3, 13, 6), `0.04%` = c(1, 2, 3, 4, 5, 5, 6, 3, 7, 8, 9, 10,
11, 9, 10, 12, 5, 13, 12, 7, 9, 4, 3, 12, 5)), .Names = c("0%",
"0.01%", "0.02%", "0.03%", "0.04%"), row.names = c(NA, -25L
), class = c("tbl_df", "tbl", "data.frame")))), .Names = c("group", "data", "h_candidates", "assignment"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -3L))
With the data structured like above I would like to change all values within assignment data.frames that appears less than k times (let's say k = 5) in a column.
So I need a solution that takes subsequent data.frames, then subsequent columns within a data.frame, check which values appears less than 5 times in a column and if there are any just replace them with 0.
At best, the solution would involve tidyverse functions. I think that nested purrr::map, as well as dplyr::mutate are needed here, but don't know how to count appearances within a column and replace the values then.
You can use purrr::map() to loop over the list column with the dataframes,
and then purrr::modify() to loop over each column in each dataframe. Then
it's just a matter of defining a function that counts occurences of values in
a vector, and replaces them if the count is less than k:
library(tidyverse)
ex %>%
mutate(assignment = map(assignment, modify, function(x, k) {
n <- table(x)[as.character(x)]
replace(x, n < k, 0)
}, k = 5))
#> # A tibble: 3 x 4
#> group data h_candidates assignment
#> <chr> <list> <list> <list>
#> 1 Group A <tibble [25 x 4]> <dbl [6]> <tibble [25 x 5]>
#> 2 Group B <tibble [25 x 4]> <dbl [6]> <tibble [25 x 5]>
#> 3 Group C <tibble [25 x 4]> <dbl [6]> <tibble [25 x 5]>
We can also define a couple of helper functions to make this more readable:
# Replace elements in x given by f(x) with val
replace_if <- function(x, f, val, ...) {
replace(x, f(x, ...), val)
}
appears_less_than <- function(x, k) {
table(x)[as.character(x)] < k
}
Combining these two functions gets what we are after:
replace_if(c(1, 1, 2, 3), appears_less_than, k = 2, 0)
#> [1] 1 1 0 0
Now all that remains is to put the pieces together:
res <- ex %>%
mutate(assignment = map(assignment, modify, replace_if,
appears_less_than, k = 3, 0))
As #thothal mentioned, there aren't any values in your data that occur more
than 4 times in your data, but with k = 3 we can have a look at the result
(to illustrate, just the 3rd dataframe in assignment):
res %>% pluck("assignment", 3)
#> # A tibble: 25 x 5
#> `0%` `0.01%` `0.02%` `0.03%` `0.04%`
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0 0 0 0 0
#> 2 0 0 0 0 0
#> 3 0 0 0 3 3
#> 4 0 0 0 0 0
#> 5 0 0 5 0 5
#> 6 0 0 0 0 5
#> 7 0 0 0 0 0
#> 8 0 0 0 3 3
#> 9 0 0 0 0 0
#> 10 0 0 5 0 0
#> # ... with 15 more rows
Finally, we could also use a scoped mutate_at() to further reduce some of
the excess syntax:
ex %>%
mutate_at(vars(assignment), map, modify,
replace_if, appears_less_than, k = 3, 0)
Created on 2018-08-08 by the reprex package (v0.2.0.9000).
This should do the trick:
library(tidyverse)
ex %>%
mutate(
assignment = map(assignment,
~ rowid_to_column(.x, "id") %>%
gather(key, value, -id) %>%
group_by(key) %>%
add_count(value) %>%
mutate(value = ifelse(n < 5, 0, n)) %>%
select(-n) %>%
spread(key, value) %>%
select(-id)
)
)
Note in your example there is no single value appearing more than 4 times.
Explanation
You map over all assignment data.frames
For each data.frame you first add an id column (needed for gather/spread)
Then you gather all columns butidinto akey(former column names)value` (the values) pair
For each group of former columns (now in key) you add a counter of the values in value
Then you replace occurrences which appear less than 5 times by 0
You remove n (the counter)
spread the data back into the original format
Remove the id column

leaflet R popup suddenly changed output?

I´m working on a leaflet map in r that visualizes data from a survey onto the map. You can get a look of how it looked over here: https://maglin.shinyapps.io/UM33/ . As you can see if you click on an area you get the name of thea area and the median score on the various questions in Swedish, for example this...
>! Område: Eds Glesbygd
Fler kultur­ och fritidsaktiviteter för äldre : 7.9
Fler kultur­ och fritidsaktiviteter för barn och ungdomar : 8.7
Förbättra äldreomsorgen i kommunen : 8.9
Fler ungdomsgårdar och fältassistenter : 9
Minska barngrupperna i förskolan : 9.9
But after some changes in the program I get this instead...
>!Område: 1:43
Bevara existerande större grönområden : c(5, 9.4, 9.6, 10.4, 8.7, 10.8, 8, 9.8, 7.3, 9.7, 12, 9, 10.1, 9.3, 9.4, 9.7, 8.5, 9.7, 10, 1, 8.4, 9.1, 10.2, 6.2, 8, 10.1, 11.5, 10.8, 9.7, 8.7, 10.3, 9.6, 10.6, 10.9, 10.9, 10, 10.7, 8, 9.4, 10.9, 6, 9.6, 14)
Anlägga parker i existerande stadsdelar : c(8, 8.1, 9.1, 9.4, 7.1, 9.6, 7.8, 9.4, 7.2, 7.4, 9, 8.2, 6.7, 8.4, 9, 9, 8.6, 8, 8, 3, 7.8, 7.8, 8, 5.2, 6.7, 8.1, 8.2, 8.9, 7.5, 7.3, 8.8, 7.7, 7.8, 7.5, 7.8, 10, 8.2, 5.7, 7.8, 7, 8, 8.2, 7)
Bygga bostäder nära grönområden : c(11, 7.7, 8.3, 6.9, 7.3, 6.6, 5.2, 7.6, 8.5, 7.5, 7.5, 7.4, 7.5, 8.7, 7.3, 11.3, 8.2, 8, 9, 13, 6.8, 6.7, 8, 9.2, 11, 7.2, 5.8, 7.5, 6.3, 8.3, 7.6, 8.1, 8.4, 9.1, 7.5, 13, 7.3, 11, 8.6, 5.9, 9, 7.3, 7)
Rusta upp befintliga parker : c(6, 9.4, 9.6, 10.7, 8.1, 9.9, 8.8, 8.8, 6.9, 9.5, 9, 9.1, 9.9, 8.3, 8.9, 11, 9.9, 9.7, 6, 12, 8.8, 9.4, 9.3, 9.5, 10, 9, 8.9, 9.6, 9.6, 8.5, 9.2, 8.5, 9.2, 9.3, 9, 14, 9.9, 9.7, 9.3, 10.3, 6, 9.7, 7)
Skapa bättre tillgänglighet till större grönområden : c(7, 8.1, 8.7, 9.2, 8.1, 9.1, 7.4, 8.5, 8.5, 8, 9.5, 7.2, 8.6, 7.6, 7.9, 8, 7, 8.7, 9, 13, 7.2, 7.3, 9, 6.2, 8.3, 8.5, 8.4, 9.1, 8.2, 7, 8.9, 8.2, 7.8, 7.8, 8, 13, 8.7, 9, 8.2, 8.4, 8, 8.3, 7)
The popup seems to show all the medians for every area instead of just the one you clicked on. This is an example of how the data looks when I save it inside an reactive variable...
Area X1a X1b X1c X1d X1e favorit
(fctr) (dbl) (dbl) (dbl) (dbl) (dbl) (chr)
1 Antuna /Älvsunda 5.0 8.0 11.0 6.0 7.0 X1c
2 Brunnby/Vik 9.4 8.1 7.7 9.4 8.1 X1a
3 Carlslund/Brunnby Park 9.6 9.1 8.3 9.6 8.7 X1a
4 Dragonvägen 10.4 9.4 6.9 10.7 9.2 X1d
5 Eds Glesbygd 8.7 7.1 7.3 8.1 8.1 X1a
And this is how the data looks when I print it out just before it gets feed into the addPolygons(popup) function...
>!"<Strong>Område: </strong> 1:43 <br><Strong> Bevara existerande större grönområden :</strong> c(5, 9.4, 9.6, 10.4, 8.7, 10.8, 8, 9.8, 7.3, 9.7, 12, 9, 10.1, 9.3, 9.4, 9.7, 8.5, 9.7, 10, 1, 8.4, 9.1, 10.2, 6.2, 8, 10.1, 11.5, 10.8, 9.7, 8.7, 10.3, 9.6, 10.6, 10.9, 10.9, 10, 10.7, 8, 9.4, 10.9, 6, 9.6, 14) <br><strong> Anlägga parker i existerande stadsdelar :</strong> c(8, 8.1, 9.1, 9.4, 7.1, 9.6, 7.8, 9.4, 7.2, 7.4, 9, 8.2, 6.7, 8.4, 9, 9, 8.6, 8, 8, 3, 7.8, 7.8, 8, 5.2, 6.7, 8.1, 8.2, 8.9, 7.5, 7.3, 8.8, 7.7, 7.8, 7.5, 7.8, 10, 8.2, 5.7, 7.8, 7, 8, 8.2, 7) <br><strong> Bygga bostäder nära grönområden :</strong> c(11, 7.7, 8.3, 6.9, 7.3, 6.6, 5.2, 7.6, 8.5, 7.5, 7.5, 7.4, 7.5, 8.7, 7.3, 11.3, 8.2, 8, 9, 13, 6.8, 6.7, 8, 9.2, 11, 7.2, 5.8, 7.5, 6.3, 8.3, 7.6, 8.1, 8.4, 9.1, 7.5, 13, 7.3, 11, 8.6, 5.9, 9, 7.3, 7) <br><strong> Rusta upp befintliga parker :</strong> c(6, 9.4, 9.6, 10.7, 8.1, 9.9, 8.8, 8.8, 6.9, 9.5, 9, 9.1, 9.9, 8.3, 8.9, 11, 9.9, 9.7, 6, 12, 8.8, 9.4, 9.3, 9.5, 10, 9, 8.9, 9.6, 9.6, 8.5, 9.2, 8.5, 9.2, 9.3, 9, 14, 9.9, 9.7, 9.3, 10.3, 6, 9.7, 7) <br><strong> Skapa bättre tillgänglighet till större grönområden :</strong> c(7, 8.1, 8.7, 9.2, 8.1, 9.1, 7.4, 8.5, 8.5, 8, 9.5, 7.2, 8.6, 7.6, 7.9, 8, 7, 8.7, 9, 13, 7.2, 7.3, 9, 6.2, 8.3, 8.5, 8.4, 9.1, 8.2, 7, 8.9, 8.2, 7.8, 7.8, 8, 13, 8.7, 9, 8.2, 8.4, 8, 8.3, 7)"
Has the dataset been turned into a factor or something? I can supply more code if needed, but I didn´t want to spam the OP with to much, The spoiler functions is messing with me.
EDIT1: So I have setup a project based on an old version that works and started looking for differences between the two projects. One difference so far is that there is a slight difference in the variable that is used to build the popup output...
In my current(faulty) project, this is what you get when you print out the variable
>print(var)
Source: local data frame [43 x 7]
Area X1a X1b X1c X1d X1e favorit
(fctr) (dbl) (dbl) (dbl) (dbl) (dbl) (chr)
1 Antuna /Älvsunda 5 8 11 6 7 X1c
2 Brunnby/Vik 9 8 8 9 8 X1a
3 Carlslund/Brunnby Park 10 9 8 10 9 X1a
4 Dragonvägen 10 9 7 11 9 X1d
5 Eds Glesbygd 9 7 7 8 8 X1a
.. ... ... ... ... ... ... ...
In the older but working version the variable looks like this...
>print(var)
Area X1a X1b X1c X1d X1e favorit
1 Antuna /Älvsunda 5 8 11 6 7 X1c
2 Brunnby/Vik 9 8 8 9 8 X1a
3 Carlslund/Brunnby Park 10 9 8 10 9 X1a
4 Dragonvägen 10 9 7 11 9 X1d
5 Eds Glesbygd 9 7 7 8 8 X1a
Have I accidentally changed a file/object type here that makes scrambles things up?
Edit2: I seem to have solved the problem by saving the dataset that (var) reads from in .csv format and then reading it in again, Any got a clue why that works?
Edit3: Seems the change happens when I call the plyr rename function, that seems to garble the output.

Resources