Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的Smartbind日期格式和错误_R_Date_Append - Fatal编程技术网

R中的Smartbind日期格式和错误

R中的Smartbind日期格式和错误,r,date,append,R,Date,Append,使用smartbind附加两个数据集时出错。首先,我非常确定我得到的错误: > Error in as.vector(x, mode) : invalid 'mode' argument 来自两个数据集中的日期变量。其原始格式中的日期变量为:月/日/年。在使用as.Date和format导入数据后,我转换了变量 > rs.month$xdeeddt <- as.Date(rs.month$xdeeddt, "%m/%d/%Y") > rs.month$deed.year

使用smartbind附加两个数据集时出错。首先,我非常确定我得到的错误:

> Error in as.vector(x, mode) : invalid 'mode' argument
来自两个数据集中的日期变量。其原始格式中的日期变量为:月/日/年。在使用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"))
日期转换应用于两个数据集(两个数据集的原始数据格式相同)。当我尝试使用gtools包中的smartbind来附加它返回的两个数据集时,会出现上述错误。我从这两个数据集中删除了日期、月、日和年变量,并能够使用smartbind成功地追加数据集


关于如何使用日期变量附加数据集的任何建议…?

我是在两个数据帧的智能绑定过程中搜索相同的错误消息后来到这里的。上面的讨论虽然对解决方案没有那么决定性,但确实帮助我克服了这个错误

我的两个数据帧都包含POSIXct日期对象。这些仅仅是一个从epoch开始的单XY秒的数字向量,以及一些属性,它们提供了将向量解释为日期对象所需的结构。解决方案只是从该变量中剥离属性,执行smartbind,然后恢复属性:

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

this.atts您正在运行哪个版本的
gtools
?我看到了
gtools_3.1.1
中的错误,但没有
gtools_3.4.1
我有3.0.0版,我会更新并尝试。
these.atts <- attributes(df1$date)
attributes(df1$date) <- NULL
attributes(df2$date) <- NULL
df1 <- smartbind(df1,df2)
attributes(df1$date) <- these.atts