Search code examples
rdatetype-conversionfinancequantitative-finance

Dates as integers? How to convert from integer to date again?


I'm trying to do an analysis of the BTC price here in Brazil, and compare it with other 4 countries..

So I've found quandl and downloaded their .csv data for both countries.

Each .csv has 6 columns:

  1. Date
  2. 24h.Average
  3. Ask
  4. Bid
  5. Last
  6. Total.Volume

Well, I'm trying to make a new table with:

  1. BTCBRL$Date
  2. BTCBRL$Last
  3. BTCUSD$Last
  4. BTCCNY$Last
  5. BTCEUR$Last

So I wrote:

lastPrices <- cbind(BTCBRL$Date, BTCBRL$Last, BTCUSD$Last, BTCCNY$Last, BTCEUR$Last)

But then my date that once was 2015-07-05, just became 656..

What's an efficient to deal with it? Preferably overwriting it in the same table..


Solution

  • Use data.frame() rather than cbind() if you want to preserve mixed types (ie have both dates and numeric values). The latter returns a matrix and a matrix can only hold a single atomic data type so it converts everything to numeric.