How to Convert String-Type Year-Month Data to Date Type

This article explains how to convert string-type values representing year and month into date-type data.

When you examine the column, you can confirm that the first row, for example, is displayed in the format “2020/1”, indicating it is year-month format data.

Since this type of data is in string format, it is not suitable for date-based operations such as aggregation by year. Therefore, it is necessary to convert this year-month format data into date-type data.

To convert year-month format data to date type, select “Convert Data Type” from the header menu of the year-month column, then choose “Convert to Date / POSIXct (Date/Time) Type”, and for this case, since it is a string format containing year and month information, select “Year, Month”.

The calculation editor will then be displayed with the formula ym(Date) already entered.

The ym function is a function that converts text containing only year and month information into date type. In this conversion, the date is automatically set as the first day of that month.

After completing the settings, by clicking the Run button, you can confirm that the year-month data has been converted to date-type data.