Based on the code and data (obtained from rayshader
tutorial website) provided in the post, I am getting the error shown below, even though the object
Year
does exist as a column in the dataframe, melt_measles
.
Why is it so and how can it be fixed?
Error:
Error in ifelse(Year == 2019 & !(Month %in% c("January", "February", "March")), :
object 'Year' not found
Code:
library(tidyverse)
library(reshape2)
measles = read_csv("https://tylermw.com/data/measles_country_2011_2019.csv")
melt_measles = melt(measles, id.vars = c("Year", "Country", "Region", "ISO3"))
melt_measles$Month = melt_measles$variable
melt_measles$cases = melt_measles$value
melt_measles %>%
group_by(Year, Month) %>%
summarize(totalcases = sum(cases,na.rm = TRUE)) %>%
mutate(totalcases = ifelse(Year == 2019 & !(Month %in% c("January","February","March")), NA, totalcases))