[R] Trying to avoid the loop while merging two data frames

Giorgio Garziano giorgio.garziano at ericsson.com
Tue Dec 22 20:29:06 CET 2015


Library dplyr to use arrange() for ordering, in the case.

library(dplyr)

result.order <- arrange(result, d, version, a, b, c)
dim(result.order)
[1] 3000    5

head(result.order)
             d version            a              b           c
1 -2.986456069       1 0.2236414154 0.004258038663 1.089406822
2 -2.986456069       1 0.2236414154 0.004258038663 1.089406822
3 -2.986456069       1 0.2236414154 0.004258038663 1.089406822
4 -2.986456069       1 0.2236414154 0.004258038663 1.089406822
5 -2.986456069       1 0.2236414154 0.004258038663 1.089406822
6 -2.986456069       3 0.2236414154 0.004258038663 1.089406822


my.merge <- merge(myinfo, mydata, by="version")
result2 <- my.merge[,c("d", "version", "a", "b", "c")]
result2.order <- arrange(result2, d, version, a, b, c)
dim(result2.order)
[1] 3000    5

head(result2.order)
             d version            a              b           c
1 -2.986456069       1 0.2236414154 0.004258038663 1.089406822
2 -2.986456069       1 0.2236414154 0.004258038663 1.089406822
3 -2.986456069       1 0.2236414154 0.004258038663 1.089406822
4 -2.986456069       1 0.2236414154 0.004258038663 1.089406822
5 -2.986456069       1 0.2236414154 0.004258038663 1.089406822
6 -2.986456069       3 0.2236414154 0.004258038663 1.089406822

all.equal(result.order, result2.order)
[1] TRUE


--

GG

	[[alternative HTML version deleted]]



More information about the R-help mailing list