0

我有以下数据框

DateBA<-structure(list(PUBID = c(1, 8, 9, 10, 28, 31, 32, 33, 34, 35), 
    CVC_BA_DEGREE = c(281, 282, 305, 293, 317, 293, 281, 282, 
    329, 321)), datalabel = "", time.stamp = "19 Sep 2013 14:32", .Names = c("PUBID", 
"CVC_BA_DEGREE"), formats = c("%9.0g", "%9.0g"), types = c(254L, 
254L), val.labels = c("vlR0000100", ""), var.labels = c("PUBID - YTH ID CODE 1997", 
"CVC_BA_DEGREE"), version = 12L, label.table = structure(list(
    vlR0000100 = structure(0L, .Names = "0")), .Names = "vlR0000100"), row.names = c(NA, 
10L), class = "data.frame")

我想将 DateBA$CVC_BA_DEGREE 转换为更可行的格式(月-年)

我知道 1980 年 1 月 == 1 ;1980 年 2 月==2;1998 年 12 月 == 228

谢谢您的帮助!

4

1 回答 1

3

打包试试yearmonzooFrom ?yearmon: "yearmon" 类用于表示月度数据。内部保存数据为年加 0 表示 1 月,1/12 表示 2 月,2/12 表示 3 月,依此类推

library(zoo)
yearmon <- as.yearmon(1980 + seq(0, 227)/12)

在@eddi 的评论之后进行编辑
,当我阅读问题并就……其他事情给出答案时,我很草率……对不起!

这是@eddi 的正确答案(谢谢!)

as.yearmon(1980 + DateBA$CVC_BA_DEGREE/12)
于 2013-09-19T18:50:54.650 回答