Quantcast
Channel: Merging data frames in R: results not sorted. - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Merging data frames in R: results not sorted.

$
0
0

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  l1 b  2 NA NA2 c  3  5 NA3 m  1 NA NA4 d NA  6  85 n NA  4 NA6 a NA NA  97 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. ThanksRafael


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images