我有兩個我想合併的大數據幀列表。這是一個數據樣本。r:合併兩個數據幀的列表
list1 = list(data.frame(Wvlgth = c(337, 337.5, 338, 338.5, 339, 339.5),
Global = c(".9923+00",".01245+00", ".0005+00", ".33421E+00", ".74361+00", ".129342+00"),
group = c(0,0,0,0,0,0)),
data.frame(Wvlgth = c(337, 337.5, 338, 338.5, 339, 339.5),
Global = c(".1284+00",".0098+00", ".7853+00", ".2311+00", ".1211+00", ".75345+00"),
group = c(1,1,1,1,1,1)))
list2 = list(data.frame(Wvlgth = c(337, 337.5, 338, 339),
time = c("13.445","13.445", "13.445", "13.445"),
IRD = c(.01324, .34565, .92395, .67489)),
data.frame(Wvlgth = c(337, 337.5, 338, 339),
time = c("13.45361","13.45361", "13.45361", "13.45361"),
IRD = c(.20981, .98703, .54092, .38567)))
我想合併與list2中的每個數據幀列表1中的每個數據幀,由「Wvlgth」,讓這樣的事情:
Wvlgth time IRD Global group
337 13.445 0.01324 .9923+00 0
337.5 13.445 0.34565 .01245+00 0
338 13.445 0.92395 .0005+00 0
339 13.445 0.67489 .74361+00 0
337 13.45361 0.20981 .1284+00 1
337.5 13.45361 0.98703 .0098+00 1
338 13.45361 0.54092 .7853+00 1
338.5 13.45361 0.38567 .2311+00 1
我想使用一個內連接因爲dataframes list1沒有與list2的數據幀相同的行數。
我嘗試了使用dplyr從this question,接受的答案,但它最終以奇怪的方式合併它們,我不太確定發生了什麼。它看起來像水平合併它們而不是垂直...?
> c(list1, list2) %>%
Reduce(function(dtf1, dtf2) inner_join(dtf1, dtf2, by="Wvlgth"), .)
Wvlgth Global.x group.x Global.y group.y time.x IRD.x time.y
1 337.0 .9923+00 0 .1284+00 1 13.445 0.01324 13.45361
2 337.5 .01245+00 0 .0098+00 1 13.445 0.34565 13.45361
3 338.0 .0005+00 0 .7853+00 1 13.445 0.92395 13.45361
4 339.0 .74361+00 0 .1211+00 1 13.445 0.67489 13.45361
IRD.y
1 0.20981
2 0.98703
3 0.54092
4 0.38567
這看起來不錯!謝謝! – ale19