Date issue on imported data

I am new to using Rstudio and I am having an issue with the date of my data.

My excel sheet has the columns titled with dates (Feb-03, Mar-03, Apr-03...), but when i import it onto RStudio it is turned into (37653, 37681, 37712 ...). I hope you can see the picture attached.

How can I change this so that my columns have dates? What is the easiest way?


Thanks in advance.

This is a fairly tricky subject. For starters - dates in Excel are actually numbers, in the background (the number of days since 1 Jan 1900. See How Dates Work in Excel - The Calendar System Explained + Video - Excel Campus
It's just that you can choose how to display them differently in Excel, as Feb-03 or 02-03 or 02/03 etc

If you have dates as data in columns, it's probably best to use read_csv from the package tidyverse. However, in your case, if you just want the dates to show up as column names, you could put quotation marks in your Excel file: "Feb-03", "Mar-03" etc. R will read that in as characters / words. Keep in mind that if you ever want to sort these names, R will not recognize them as dates and will sort them alphabetically.

PS I don't know exactly what kind of data you are working with, but if you need the dates to be recognizable as dates, you might want to re-format the data to have ID as column names, and have the date as a column.

1 Like

Thank you very much for that! I will try out what you suggested.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.