How to get a result of the correct class when concatenating data in R? -
i have found c
, rbind
class of result based on class of first argument. has caused problem me because presence of na
first argument coerces date
vectors numeric
vectors. compare result of these 2 class
calls:
x <- sys.date() y <- na class(c(x, y)) # "date" class(c(y, x)) # "numeric"
and likewise rbind
:
x <- data.frame(column=sys.date()) y <- data.frame(column=na) class(rbind(x, y)$column) # "date" class(rbind(y, x)$column) # "numeric"
how can ensure result of these concatenations date
vector, regardless of order of arguments?
coerce first argument desired class:
c(as.date(y), x) c(as.date(x), y)
Comments
Post a Comment