Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to rename the columns of a large data table to dates

I am working from an nc file and after extracting the data to a matrix the time variable is the column variable for this it just gave it a number 1:2087 for the range of time for the dataset. I would like to rename it to the date that they should be (starting at 1981/12/31 to 2021/12/31 where each column is a week) I tried to change the names by using

colnames(tmp_mat) <- rep(seq(as.Date('1982-01-05'), as.Date('2021-12-28'), by = 'weeks'))

this changed the column names but it changed it to a number (the number of days for that date since 1971/01/01.
Does anyone have any suggestions in how to make this work

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your data is a matrix , you have to change it to data.frame then apply your code

tmp_mat = data.frame(tmp_mat)

colnames(tmp_mat) <- rep(seq(as.Date('1982-01-05'), as.Date('2021-12-28'), by = 'weeks'))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading