> setwd("G:/RBook/")
> f1 <- read.table(file = "f1.txt", header = TRUE)
> f1id <- read.table(file = "f1id.txt", header = TRUE)
> f2 <- read.table(file = "f2.txt", header = TRUE)
> f2id <- read.table(file = "f2id.txt", header = TRUE)
>
>
> new <- merge(f1, f1id, by = "id", all = TRUE)
>
> new
id i001 i002 i003 fname lname
1 123 3 2 4 John W
2 258 4 3 5 Jada W
3 321 4 5 3 Tana W
>
> id <- new$id
> fname <- new$fname
> lname <- new$lname
> i001 <- new$i001
> i002 <- new$i002
> i003 <- new$i003
>
>
> new2 <- data.frame(fname = fname, lname = lname, id = id,
+ i001 = i001, i002 = i002, i003 = i003)
>
> new2
fname lname id i001 i002 i003
1 John W 123 3 2 4
2 Jada W 258 4 3 5
3 Tana W 321 4 5 3
>
> newid <- merge(f1id, f2id, by = c("fname", "lname"))
>
> newid
fname lname id pid
1 John W 123 989
>
>
不知道行不行。
我也是初学者,互相交流学习一下。 |