用自己的名称替换列名

时间:2016-03-16 17:52:10

标签: r text vector dataframe time-series

我用R生成了一个文本文件     write.table(矩阵(Z,byrow = F,nrow = 12)" monthly.txt",row.names = T,col.names = T) 看起来像produced

我希望该表格如此desired。我应该如何修改代码,以便V&#39和s被年份和月份名称替换,如图像2? 谢谢!

1 个答案:

答案 0 :(得分:0)

您想使用函数colnames()和rownames()

更改列名和行名
mat <- matrix(z,byrow=F,nrow=12)
colnames(mat) <- c("list","of","names","you","want","on","the", "top")
rownames(mat) <- c("list","of","names","you","want","on","the", "side")

write.table(mat,"monthly.txt",row.names=T,col.names=T)