PascalVKooten
PascalVKooten

Reputation: 21433

Weird Sys.time() when used in cbind()

Can anyone explain to me why a normal Sys.time()

> Sys.time()
[1] "2013-05-06 23:23:22 CEST"

changes into

> cbind(Sys.time(), 1:5)
            [,1] [,2]
  [1,] 1367875299    1
  [2,] 1367875299    2
  [3,] 1367875299    3
  [4,] 1367875299    4
  [5,] 1367875299    5

when using cbind?

Upvotes: 1

Views: 129

Answers (1)

eddi
eddi

Reputation: 49448

It gets converted to numeric, when you cbind (because the result is a matrix and can keep only one type of an object):

as.numeric(Sys.time())
# [1] 1367875892

Contrast with:

cbind(Sys.time(), data.frame(1:5))
           Sys.time() X1.5
#1 2013-05-06 16:33:27    1
#2 2013-05-06 16:33:27    2
#3 2013-05-06 16:33:27    3
#4 2013-05-06 16:33:27    4
#5 2013-05-06 16:33:27    5

Multiple types are ok here.

Upvotes: 2

Related Questions