2

I have two dataframes with same format looking like this:

df1)

name value score
 a     2    0.01
 b     2    2.25
 c     1    5.24

df2)

name value score
 A     2    -8.01
 B     2    -3.25
 C     1    -2.24

I want to merge these two list according to the absolute value of "score" column

output)

name value score
 A     2    -8.01
 c     1    5.24
 B     2    -3.25
 b     2    2.25
 C     1    -2.24
 a     2    0.01

Would there be a simple r code for this? I would appreciate any help. Thanks

talat
  • 68,970
  • 21
  • 126
  • 157
user2418838
  • 371
  • 3
  • 12

1 Answers1

3

rbind and order rows:

newdat <- rbind(dat1,dat2)
newdat[order(abs(newdat$score),decreasing=TRUE),]

#  name value score
#4    A     2 -8.01
#3    c     1  5.24
#5    B     2 -3.25
#2    b     2  2.25
#6    C     1 -2.24
#1    a     2  0.01
thelatemail
  • 91,185
  • 12
  • 128
  • 188