我有以下数据框
CollegeData<-structure(list(PUBID = c(1, 2, 3, 4, 6, 8, 9, 10, 11, 12), CVC_BA_DEGREE = structure(c(2003.41666666667,
NA, NA, NA, NA, 2003.5, 2005.41666666667, 2004.41666666667, NA,
NA), class = "yearmon"), FirstYear4C = c(1999, 2000, 2001, 2005,
2000, 1999, 2000, 2002, 2001, 2002)), .Names = c("PUBID", "CVC_BA_DEGREE",
"FirstYear4C"), row.names = c(NA, 10L), class = "data.frame")
我想创建一个新列,
CollegeData$TTD=CollegeData$CVC_BA_DEGREE-CollegeData$FirstYear4C
其中第一个元素是 2003-1999 年 6 月 = 4 年,第二个是 NA - 2000=NA
谢谢!