0
votes

I have the following data frame

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

I want to convert DateBA$CVC_BA_DEGREE to a more workable format (month-year)

I know that January 1980 == 1 ; February 1980==2; December 1998 == 228

Thanks for the help!

1

1 Answers

3
votes

Try yearmon in zoo package. From ?yearmon: "The "yearmon" class is used to represent monthly data. Internally it holds the data as year plus 0 for January, 1/12 for February, 2/12 for March and so on

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

edit following @eddi's comment
I was sloppy when I read the question and gave an answer on...something else...Sorry!

Here is @eddi's correct answer (thanks!)

as.yearmon(1980 + DateBA$CVC_BA_DEGREE/12)