data.frame
recycles shorter vectors to match the length of the data frame.
test1 = data.frame(x = 1:5, date = as.Date("2013-05-01"))
x date
1 1 2013-05-01
2 2 2013-05-01
3 3 2013-05-01
4 4 2013-05-01
5 5 2013-05-01
However, it does not seem to work with the chron
class:
require(chron)
test2 = data.frame(x = 1:5, time = times("08:00:00"))
Error in data.frame(x = 1:5, time = times("08:00:00")) :
arguments imply differing number of rows: 5, 1
There are workarounds, e.g. doing the recycling manually, like:
test3 = data.frame(x = 1:5, time = times(rep("08:00:00",5)))
But why doesn't the recycling work? Am I missing something here or is there a bug somewhere?