I have two data frames in R as follows:
dat1<-read.table (text=" ID Surname Name Class
12 Smith Bani B
14 Smith Adami C
13 Rose Road AB
11 Smith Cherch AC
10 Sarah Naim D
", header=TRUE)
dat2<-read.table (text=" ID Surname Name Class
12 Smith Bani A
14 Smith Adami B
13 Rose Road AB
11 Smith Cherch AC
10 Sarah Naim D
", header=TRUE)
I arrange like this separately
k1 <- arrange(dat1, Surname)
k2 <- arrange(dat2, Surname)
Now I merge dat1 and dat2 followed by arranging
k3 <- merge(dat1, dat2, by = "ID")
k4 <- arrange(k3, Surname.x)
I want to get exactly the arrangement that I get for K1 or K2 for the surname when I merge dat1 and dat2. Is it possible?