[R] relating data in two data frames

arun smartpink111 at yahoo.com
Mon Aug 20 14:43:49 CEST 2012


Hi,
Try this:
A<-data.frame(FID=c("a","a","b","b","c","c","d","d","d","d"))
B<-read.table(text="
FID Age
a      5
b      7
c      9
d      3 
",sep="",header=TRUE) 
library(plyr)
join(A,B,type="inner")
Joining by: FID
   FID Age
1    a   5
2    a   5
3    b   7
4    b   7
5    c   9
6    c   9
7    d   3
8    d   3
9    d   3
10   d   3
A.K.



----- Original Message -----
From: Sapana Lohani <lohani.sapana at ymail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Sunday, August 19, 2012 8:56 PM
Subject: [R] relating data in two data frames

Hi, 


My data.frame "A" has FID like this

FID

a

a
b
b
b
c
c
d
d
d
d

Now my second data.frame "B" has age value for a, b, c, d like

FID Age

a      5

b      7
c      9
d      3

How can search for the Age column in "B" and replace the values in "A" so that my new "A" looks like this

FID Age

a      5
a      5
b      7
b      7
b      7
c      9
c      9
d      3
d      3
d      3
d      3

Thanks you

    [[alternative HTML version deleted]]


______________________________________________
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.





More information about the R-help mailing list