Thanks for reply.
The following code is working but only patially. How to get the condensed
values separated by comma.
dataframe1 = data.frame(cbind(Src = c(1,1,1,2,3), Target1 =
c('aaa','bbb','ccc','aaa','ddd')));
dataframe2 = data.frame(cbind(Src = c(2,3,4,4,4), Target2 =
c('aaaa','dddd','bbbb','eeee','ffff')));
dataframe3 = data.frame(cbind(Src = c(1,3,5,6,6), Target3 =
c('xx','yy','zz','tt','uu')));
merge(dataframe3, merge(dataframe1,dataframe2, by = 'Src', all=TRUE), by =
'Src', all=TRUE)
1> merge(dataframe3, merge(dataframe1,dataframe2, by = 'Src', all=TRUE), by
= 'Src', all=TRUE)
Src Target3 Target1 Target2
1 1 xx aaa <NA>
2 1 xx bbb <NA>
3 1 xx ccc <NA>
4 3 yy ddd dddd
5 5 zz <NA> <NA>
6 6 tt <NA> <NA>
7 6 uu <NA> <NA>
8 2 <NA> aaa aaaa
9 4 <NA> <NA> bbbb
10 4 <NA> <NA> eeee
11 4 <NA> <NA> ffff
Thanks
--
M
On Mon, Jun 13, 2011 at 6:35 PM, Dr. D. P. Kreil (Boku) <
[email protected]> wrote:
> Hi, try
>
> ?merge
>
> Best,
> David.
>
>
> On 13 June 2011 23:48, Mary Kindall <[email protected]> wrote:
> > Hi R users,
> > I am new to R and am trying to merge data frames in the following way.
> > Suppose I have n data frames each with two fields. Field 1 is common
> among
> > data frames but may have different entries. Field 2 is different.
> >
> >
> > Data frame 1:
> >
> > Src Target1
> > 1 aaa
> > 1 bbb
> > 1 ccc
> > 2 aaa
> > 3 ddd
> >
> >
> > Data frame 2:
> >
> > Src Target2
> > 2 aaaa
> > 3 dddd
> > 4 bbbb
> > 4 eeee
> > 4 ffff
> >
> >
> > Data frame 3:
> >
> > Src Target3
> > 1 xx
> > 3 yy
> > 5 zz
> > 6 tt
> > 6 uu
> >
> > And so on...
> >
> > I want to convert this into a data frame something similar to:
> > Src Target1 target2
> > target3
> > 1 aaa,bbb,ccc -
> xx
> >
> > 2 aaa aaaa
> -
> > 3 ddd dddd
> > yy
> > 4 - bbbb,eeee,ffff
> -
> >
> > 5 -
> > - zz
> > 6 -
> > - tt,uu
> >
> >
> > Basically I am trying to make a consolidated table.
> >
> > Help appreciated.
> > Thanks
> > M
> >
> >
> > -------------
> > Mary Kindall
> > Yorktown Heights
> > USA
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [email protected] 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.
> >
>
--
-------------
Mary Kindall
Yorktown Heights, NY
USA
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.