I want to pull my hair out on this one...
I read in code like this
holidays <- read.csv("~/xxx/holiday_sample.csv") %>%
rename(DATE = "ï..DATE") %>%
mutate(DATE = as.Date(DATE,format = "%m/%d/%Y"))
##looks like this
structure(list(DATE = structure(c(17532, 17533, 17534, 17546,
17547, 17548, 17549, 17575, 17576, 17577, 17620, 17621, 17622,
17678, 17679, 17680, 17681, 17682, 17713, 17714, 17715, 17716,
17717, 17774, 17775, 17776, 17777, 17778, 17812, 17847, 17855,
17856, 17857, 17858, 17859, 17860, 17884, 17885, 17886, 17887,
17888, 17889, 17890, 17891, 17892, 17893, 17894, 17895, 17896
), class = "Date"), REASON = c("New Years Day", "New Years Travel",
"New Years Travel", "Lee-Jackson Day", "Lee-Jackson-King Travel Day",
"Lee-Jackson-King Travel Day", "Martin Luther King, Jr. Day",
"Presidents Day Travel", "Presidents Day Travel", "Presidents Day",
"Easter Travel", "Easter Travel", "Easter", "Memorial Day Travel",
"Memorial Day Travel", "Memorial Day Travel", "Memorial Day",
"Memorial Day Travel", "Independence Day Travel", "Independence Day Travel",
"Independence Day Travel", "Independence Day", "Independence Day Travel",
"Labor Day Travel", "Labor Day Travel", "Labor Day Travel", "Labor Day",
"Labor Day Travel", "Columbus Day", "Veterans Day", "Thanksgiving Travel",
"Thanksgiving Travel", "Thanksgiving Day", "Thanksgiving Travel",
"Thanksgiving Travel", "Thanksgiving Travel", "Christmas Travel",
"Christmas Travel", "Christmas Travel", "Christmas Travel", "Christmas Travel",
"Christmas Travel", "Christmas Day", "Christmas Travel", "Christmas Travel",
"Christmas Travel", "Christmas Travel", "Christmas Travel", "New Years Travel"
)), class = "data.frame", row.names = c(NA, -49L))
And I want to loop thru another df to see which rows happen on a holiday.
bottleneck2 <- structure(list(startTime = structure(c(1519903920, 1519905060,
1519913640), class = c("POSIXct", "POSIXt"), tzone = "America/New_York"),
endTime = structure(c(1519904880, 1519912200, 1519914540), class = c("POSIXct",
"POSIXt"), tzone = "America/New_York"), impact = c(92.17,
616.43, 63.69), impactPercent = c(184.15, 1495.17, 138.69
), impactSpeedDiff = c(3587.72, 25726.22, 2616.01), maxQueueLength = c(5.76053,
5.76053, 4.829511), tmcs = list(c("110N04623", "110-04623",
"110N04624", "110-04624", "110N04625", "110-04625", "110N04626",
"110-04626", "110N04627"), c("110N04623", "110-04623", "110N04624",
"110-04624", "110N04625", "110-04625", "110N04626", "110-04626",
"110N04627"), c("110N04623", "110-04623", "110N04624", "110-04624",
"110N04625", "110-04625", "110N04626", "110-04626")), early_startTime = structure(c(1519903620,
1519904760, 1519913340), class = c("POSIXct", "POSIXt"), tzone = "America/New_York")), row.names = c(NA,
3L), class = "data.frame")
But when I run the following I get a syntax error which makes zero sense....
holiday_match <- lapply(1:nrow(bottleneck2), function(x) {
bottleneck_row <- bottleneck2[x,]
holidays[which(holidays$DATE = as.Date(bottleneck_row$early_startTime) |
holidays$DATE = as.Date(bottleneck_row$endTime) == TRUE),]
})
ERROR: Error: unexpected '}' in " }"
And then when I am saving the file in R I get another error.
Error in source("~/xxx/example.R") :
~/xxx/example.R:226:32: unexpected '='
225: bottleneck_row <- bottleneck2[x,]
226: holidays[which(holidays$DATE =
Saw another post saying it could be a Unicode mismatch but retyped it twice and no shot. This is a copy and paste of another loop in the file which works perfectly....