Monday, 15 June 2015

Smartbind date format and error in R -



Smartbind date format and error in R -

i'm getting error using smartbind append 2 datasets. first, i'm pretty sure error i'm getting:

> error in as.vector(x, mode) : invalid 'mode' argument

is coming date variable in both datasets. date variable in it's raw format such: month/day/year. transformed variable after importing info using as.date , format

> rs.month$xdeeddt <- as.date(rs.month$xdeeddt, "%m/%d/%y") > rs.month$deed.year <- as.numeric(format(rs.month$xdeeddt, format = "%y")) > rs.month$deed.day <- as.numeric(format(rs.month$xdeeddt, format = "%d")) > rs.month$deed.month <- as.numeric(format(rs.month$xdeeddt, format = "%m"))

the resulting date variable such:

> [1] "2014-03-01" "2014-03-13" "2014-01-09" "2013-10-09"

the transformation date applied both datasets (the format of raw info identical both datasets). when seek utilize smartbind, gtools package, append 2 datasets returns error above. removed date, month, day, , year variables both datasets , able append datasets smartbind.

any suggestions on how can append datasets date variables.....?

i came here after googling same error message during smartbind of 2 info frames. give-and-take above, while not conclusive solution, helped me move through error.

both info frames contain posixct date objects. numeric vector of unixy seconds-since-epoch, along couple of attributes provide construction needed interpret vector date object. solution strip attributes variable, perform smartbind, , restore attributes:

these.atts <- attributes(df1$date) attributes(df1$date) <- null attributes(df2$date) <- null df1 <- smartbind(df1,df2) attributes(df1$date) <- these.atts

i hope helps someone, sometime.

-andy

r date append

No comments:

Post a Comment