This is based on an example on Simultaneously merge multiple data.frames in a list .
I want to merge multiple data frames with a single column in common -- can do that with the example provided on the link.
But it seems that using the parameter sort=TRUE
has no effect. Here is the short, reproducible code:
x <- data.frame(i = c("m","b","c"), j = 1:3)
y <- data.frame(i = c("n","c","d"), k = 4:6)
z <- data.frame(i = c("o","d","a"), l = 7:9)
Merging all them without sorting:
Reduce(function(dtf1, dtf2) merge(dtf1, dtf2, by = "i", all = TRUE),
list(x,y,z))
Gives me
i j k l
1 b 2 NA NA
2 c 3 5 NA
3 m 1 NA NA
4 d NA 6 8
5 n NA 4 NA
6 a NA NA 9
7 o NA NA 7
Merging all them with sorting:
Reduce(function(dtf1, dtf2) merge(dtf1, dtf2, by = "i", all = TRUE,sort = TRUE),
list(x,y,z))
Gives me the same result as above. I know I can sort the dataframe after the merging (I guess it could even be probably more efficient) but why sort = TRUE
has no effect?
I'm running R 3.4.3 under RStudio on a Mac. Thanks Rafael