0

I have two data frames with date variables. The first data frame's date variable is type "Date" in YYYY-MM-DD format. The second data frame's date variable is type "integer" in YYYYMMDD format. I am trying to convert one, or both, date variables so I can merge the two data frames by each data frame's date variable. I realize this is a multi-step process, but I'm having difficulty with creating / converting to do the merge.

The first data frame has the following code: FF$FFReportDT<-(strptime(FF$Month,format="%Y-%m-%d")), the conversion of a YYYY-MM-DD formatted "Date" variable type to a POSIXLt variable type.

The second data frame has the following code:

  lsHFIndex$FFReportDt <- strptime(lsHFIndex$ReportDt,"%Y%m%d")

....., the conversion of a YYYYMMDD formatted "Integer" variable type to a POSIXLt variable type.

When I do the merge with the following code:

lsHFIndexFF<-merge(lsHFIndex, FF, by.x="FFReportDt", by.y="FFReportDt")

I get the following error message: Error in fix.by(by.y, y) : 'by' must specify a uniquely valid column

Problem is when I look at each data frame's 'FFReportDt' variable, each looks good.

Where am I going wrong?

IRTFM
  • 258,963
  • 21
  • 364
  • 487
fibrou
  • 313
  • 1
  • 5
  • 15
  • Does this help? http://stackoverflow.com/questions/22776381/splitting-numeric-yyyymmdd-column-r/22776723#22776723 – Blue Magister Aug 04 '14 at 21:59
  • Convert to Date class first. (And pkg:lubridate has some coercion functions that are "smart" in that their authors tried to put in code that makes "educated" guesses at formatting. – IRTFM Aug 04 '14 at 22:51
  • The first data frame variable FF$Month is a Date, but the second data frame variable lsHFIndex$ReportDt is an Integer. I thought the strptime() operation created the same class variable - a POSIXlt variable, on which I could merge the two data frames. What am I doing wrong with that approach? Thanks @BondedDust for the lubridate suggestion, by the way. I will have to give that a try. – fibrou Aug 05 '14 at 14:54
  • Thanks @BondedDust! The lubridate package and the ymd function worked wonders. Appreciate all the attention. – fibrou Aug 05 '14 at 16:00

0 Answers0