screechOwl
screechOwl

Reputation: 28139

How to combine 2 Date vectors in data frame without changing format

I'm trying to put 2 vectors of dates together in one data frame but when I do they change formats. Any suggestions?

> head(starters)
    [1] "2009-01-02" "2009-02-02" "2009-03-02" "2009-04-01"
    [5] "2009-05-01" "2009-06-01"
    > head(enders)
    [1] "2009-01-30" "2009-02-27" "2009-03-31" "2009-04-30"
    [5] "2009-05-29" "2009-06-30"
    > class(enders)
    [1] "Date"
    > class(starters)
    [1] "Date"
    > comboer <- data.frame(cbind(starters, enders))
    > head(comboer)
      starters enders
    1    14246  14274
    2    14277  14302
    3    14305  14334
    4    14335  14364
    5    14365  14393
    6    14396  14425

Upvotes: 3

Views: 4834

Answers (1)

joran
joran

Reputation: 173517

A relevant section of ?cbind is:

Any classes the inputs might have are discarded (in particular, factors are replaced by their internal codes).

It's doing something similar to dates as what they describe with factors. You probably just want to do something like this:

data.frame(starters = starters, enders = enders)

Upvotes: 5

Related Questions