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
Em 23-05-2013 09:41, Keniajin Wambui escreveu:> ---------- Forwarded message ----------
> From: Keniajin Wambui <kiangati at gmail.com>
> Date: Thu, May 23, 2013 at 11:36 AM
> Subject: Merge
> To: r-help at r-project.org
>
>
> I am using R 3.01 on R Studio to merge two data sets with approx 120
> variables and the other with 140 variables but with a serialno as the
> unique identifier.
> i.e
>
> Serialno name year outcome
> 1 ken 1989 d
> 2 mary 1989 a
> 4 john 1989 a
> 5 tom 1989 a
> 6 jolly 1989 d
>
> and
>
> 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
>
> How can I merge them to a common data set without having name.x and
> name.y or year.x and year.y after merging
> --
> Mega Six Solutions
> Web Designer and Research Consultant
> Kennedy Mwai
> 25475211786
>
>
> --
> Mega Six Solutions
> Web Designer and Research Consultant
> Kennedy Mwai
> 25475211786
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>