Hi @pep, welcome to community!
reprex
- Firstly, just a note that it would be awesome if you could rewrite your post with a more reproducible example -- reprex
. Here's some advice on what that means FAQ: What's a reproducible example (`reprex`) and how do I create one?.
What happening? - Here's a nice explanation of what's going on here (gist, a Date in R is the number of days since some origin date, usually the epoch - so you need a day in addition to year and month with as.Date()
):
Here appears to be a tidyverse solution: