我有6個數據框,所有數據框都有唯一的列名,相同數量的列,並且數據是在同一時間段內收集的。根據匹配時間戳合併多個數據框
每個數據幀都有一個時間標記和分鐘平均值,但是一些數據幀中缺少數據和列長度不相等。
我想合併數據幀並排顯示全部6個數據幀,但只有在所有6個數據幀都存在數據的時候,即具有最低列數的df,即「H1_min」
> head(H1_min)
h1min h1temp h1humid h1db h1hz
1 2015-09-06 00:00:00 21.5 73.10 39.252 117.1900
2 2015-09-06 00:02:00 21.5 72.50 39.434 125.0000
3 2015-09-06 00:03:00 21.5 72.65 39.338 127.9325
4 2015-09-06 00:04:00 21.5 73.00 39.206 148.4400
5 2015-09-06 00:06:00 21.5 73.00 39.253 144.5350
6 2015-09-06 00:07:00 21.5 72.30 39.293 156.2500
其他數據框的名稱相似,但H1 = H2到H6。
dput(head(H2_min))
"2015-09-08 20:21:00", "2015-09-08 20:22:00", "2015-09-08 20:23:00",
"2015-09-08 20:24:00", "2015-09-08 20:25:00", "2015-09-08 20:26:00",
"2015-09-08 20:27:00", "2015-09-08 20:28:00", "2015-09-08 20:29:00",
"2015-09-08 20:30:00", "2015-09-08 20:31:00", "2015-09-08 20:32:00",
"2015-09-08 20:33:00", "2015-09-08 20:34:00", "2015-09-08 20:35:00"
), class = "factor"), h2temp = c(23.4, 23.4, 23.3, 23.2, 23.2,
23.1), h2humid = c(38.5, 38.3, 38.05, 38.1, 38.6, 38.6), h2db = c(38.834,
38.655, 38.679, 38.695, 38.806, 38.702), h2hz = c(191.41, 152.34,
162.11, 113.28, 121.09, 164.06)), .Names = c("h2min", "h2temp",
"h2humid", "h2db", "h2hz"), row.names = c(NA, 6L), class = "data.frame")
dput(head(H4_min))
"2015-09-08 17:10:00", "2015-09-08 17:11:00", "2015-09-08 17:12:00",
"2015-09-08 17:13:00"), class = "factor"), h4temp = c(27.2, 27.2,
27.2, 27.2, 27.2, 27.2), h4humid = c(33.5, 33.5, 33.5, 33.5,
33.5, 33.5), h4db = c(36.8225, 36.921, 36.8766666666667, 36.91,
36.8336666666667, 36.768), h4hz = c(134.765, 136.068333333333,
137.373333333333, 126.3, 139.323333333333, 128.906666666667)), .Names =
c("h4min", "h4temp", "h4humid", "h4db", "h4hz"), row.names = c(NA, 6L), class = "data.frame")
這種嘗試得到:
H_min<-merge(H1_min, H2_min, H3_min, H4_min, H5_min, H6_min, by.x = 'row.names', by.y ='h1_min')
Error in fix.by(by.y, y) : 'by' must specify a uniquely valid column
帶空格的數據很難輸入。請提供'dput(head(H1_min))'的輸出。這種額外數據框的輸出也會有所幫助。 –
當然,將它添加到第二個數據框中 – Evan
@Evan不是輸出輸出...它應該以'structure('... – pcantalupo