如何将大数据表的列重命名为日期

发布于 2025-02-11 22:06:40 字数 308 浏览 2 评论 0原文

我正在从NC文件工作,然后将数据提取到矩阵后,时间变量是列变量,为此,它在数据集的时间范围内给了它数字1:2087。我想将其重命名到应该将其重命名(从1981/12/31到2021/12/31,每列是一周的时间)我尝试通过使用

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

此更改的列名来更改名称,但它更改了它达到数字(自1971/01/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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨死的猪 2025-02-18 22:06:40

您的数据是矩阵,您必须将其更改为data.frame然后应用您的代码

tmp_mat = data.frame(tmp_mat)

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文