Home > Enterprise >  How to rename the columns of a large data table to dates
How to rename the columns of a large data table to dates

Time:07-01

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

CodePudding user response:

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'))

  • Related