Year only as Date type


I have Year as a character type variable. I am trying to change it as Date type, however, I don't want to include false months and days in order to do that. Is there any way to have just Year but also as Date type. Currently, I can only get it while including false month and day with the following code
df <- df%>%
mutate(Year = ymd(Year, truncated = 2L))

This produces the pattern 2015-01-01 for all different years with same month and day.

Thanks for your help!

Can you explain why treating the year as simply a number will not work?

1 Like

That actually is a good point. I thought because Year is a component of Date, I should first convert it to Date type.

Number should definitely work

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.