无法合并公共因子列

时间:2015-08-05 21:13:10

标签: r merge dataframe

我有两个数据框,x和y,其片段如下:

x=structure(list(area = c(104675000L, 104675000L, 104675000L, 104675000L, 
104675000L, 104675000L), date.f = structure(c(20L, 15L, 22L, 
19L, 21L, 24L), .Label = c("2010-09-08", "2010-09-09", "2010-09-10", 
"2010-09-11", "2010-09-12", "2010-09-13", "2010-09-14", "2010-09-15", 
"2010-09-16", "2010-09-17", "2010-09-18", "2010-09-19", "2010-09-20", 
"2010-09-21", "2010-09-22", "2010-09-23", "2010-09-24", "2010-09-25", 
"2010-09-26", "2010-09-27", "2010-09-28", "2010-09-29", "2010-09-30", 
"2010-10-01"), class = "factor")), .Names = c("area", "date.f"
), row.names = c(NA, 6L), class = "data.frame")

y=structure(list(vpd = c(1.59698384937354, 1.39675911630085, 1.23644210175356, 
1.43062258881502, 1.31336561596584, 1.40749398063385), date.f = structure(1:6, .Label = c("2010-08-25", 
"2010-08-26", "2010-08-27", "2010-08-28", "2010-08-29", "2010-08-30", 
"2010-08-31", "2010-09-01", "2010-09-02", "2010-09-03", "2010-09-04", 
"2010-09-05", "2010-09-06", "2010-09-07", "2010-09-08", "2010-09-09", 
"2010-09-10", "2010-09-11", "2010-09-12", "2010-09-13", "2010-09-14", 
"2010-09-15", "2010-09-16", "2010-09-17", "2010-09-18", "2010-09-19", 
"2010-09-20", "2010-09-21", "2010-09-22", "2010-09-23", "2010-09-24", 
"2010-09-25", "2010-09-26", "2010-09-27", "2010-09-28", "2010-09-29", 
"2010-09-30", "2010-10-01", "2010-10-02", "2010-10-03", "2010-10-04", 
"2010-10-05", "2010-10-06", "2010-10-07", "2010-10-08", "2010-10-09", 
"2010-10-10", "2010-10-11", "2010-10-12", "2010-10-13", "2010-10-14", 
"2010-10-15"), class = "factor")), .Names = c("vpd", "date.f"
), row.names = c("2010-08-25 23:00:00", "2010-08-26 23:00:00", 
"2010-08-27 23:00:00", "2010-08-28 23:00:00", "2010-08-29 23:00:00", 
"2010-08-30 23:00:00"), class = "data.frame")

我想在date.f列上合并,如此

merge_all(x, y, by="date.f")

但是我收到了这个错误:

fix.by(by.x,x)出错:   'by'必须将一个或多个列指定为数字,名称或逻辑

我不明白为什么这不起作用。 “date.f”列存在于两个数据帧中。

感谢您的帮助。

丹尼尔

1 个答案:

答案 0 :(得分:1)

merge_all需要一个数据框列表,而不是单独的两个:

merge_all(list(x, y), by = "date.f")

如果您只想要两个,基本合并就可以了:

merge(x, y, by = "date.f", all = TRUE)