I have some date data in the format Start_year = 2018/19, 2019/20, 2020/21 etc. I want to put it in the format 2018, 2019, 2020, as integers, for a group by clause later in the code.
select_data <- data %>%
select(Product, Start_year, Number, Amount) %>%
mutate(Avg_paid = Amount/Number)%>% #This works fine
mutate(Start_year_short = as.integer(str_trunc(Start_year, 4, c("left"))))
The error message I get is:
Problem with `mutate()` column `Start_year_short`. `Start_year_short = as.integer(str_trunc(Start_year, 4, c("left")))`. NAs introduced by coercion
If I take the mutate out and do
Start_year <- as.integer(str_trunc(Start_year, 4, c("left")))
I get an object not found error instead. I really can't work out what's going wrong.