Hello,
Try the following.
rm(list = ls())
dat1 <- read.table(text = "
Serialno name year outcome
1 ken 1989 d
2 mary 1989 a
4 john 1989 a
5 tom 1989 a
6 jolly 1989 d
", header = TRUE, stringsAsFactors = FALSE)
dat2 <- read.table(text = "
Serialno name year disch_type
11 mwai 1990 d
21 wanjiku 1990 a
43 maina 1990 a
55 john 1990 a
67 welly 1990 d
", header = TRUE, stringsAsFactors = FALSE)
res <- merge(dat1[, c(1, 4)], dat2[, c(1, 4)], all = TRUE)
res <- merge(merge(res, dat1, all.y = TRUE), merge(res, dat2, all.y =
TRUE), all = TRUE)
res <- res[, c(1, 4, 5, 2, 3)]
res
Hope this helps,
Rui Barradas