<no subject>

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

<no subject>

Marco Blanchette-3
Dear all,

I am still fairly new to R and try to analyze large tables of data generated
from genomic experiment. Currently, I am trying to plot pair of experiments
coming from different file, trying to look at the behavior of individual
feature in pair of experiment.

My problem is that I have independent list from different source and I would
like to plot the pair of value using a common key. As in this simplified
version:

table1 = list(CGID=c("CG_1","CG_3","CG_2", "CG_4", "CG_5"),
diff=c(3,5,6,4,3))

table2 = list(CGID=c("CG_2","CG_3","CG_4", "CG_1", "CG_5"),
diff=c(4,6,3,9,10))

How can link the two table trough the CGIDC column and plot the data from
the 2 tables.

Many tx

Marco Blanchette, Ph.D.

[hidden email]

Donald C. Rio's lab
Department of Molecular and Cell Biology
16 Barker Hall
University of California
Berkeley, CA 94720-3204

Tel: (510) 642-1084
Cell: (510) 847-0996
Fax: (510) 642-6062

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Merging lists on common key (was <no subject>)

Marc Schwartz (via MN)
On Wed, 2005-12-14 at 18:14 -0800, Marco Blanchette wrote:

> Dear all,
>
> I am still fairly new to R and try to analyze large tables of data generated
> from genomic experiment. Currently, I am trying to plot pair of experiments
> coming from different file, trying to look at the behavior of individual
> feature in pair of experiment.
>
> My problem is that I have independent list from different source and I would
> like to plot the pair of value using a common key. As in this simplified
> version:
>
> table1 = list(CGID=c("CG_1","CG_3","CG_2", "CG_4", "CG_5"),
> diff=c(3,5,6,4,3))
>
> table2 = list(CGID=c("CG_2","CG_3","CG_4", "CG_1", "CG_5"),
> diff=c(4,6,3,9,10))
>
> How can link the two table trough the CGIDC column and plot the data from
> the 2 tables.
>
> Many tx
>
> Marco Blanchette, Ph.D.

Marco,

Please use an informative subject when posting. It makes it easier for
folks, especially when reviewing the e-mail list archives.

There is a function called merge() which will perform SQL-like joins.

merge() will coerce the two lists to data frames, so you can do the
following:

> merge(table1, table2, by = "CGID")
  CGID diff.x diff.y
1 CG_1      3      9
2 CG_2      6      4
3 CG_3      5      6
4 CG_4      4      3
5 CG_5      3     10

The result is a join of the two lists, using CGID (quoted) as the
primary key. The two 'diff' elements are uniquely named based upon their
source objects (x and y arguments in merge()) as a suffix. The appended
suffix can be changed if required.

See ?merge for more information.

HTH,

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <no subject>

Jacques VESLOT
In reply to this post by Marco Blanchette-3
try with merge() :

table1 = data.frame( CGID=c("CG_1","CG_3","CG_2", "CG_4", "CG_5"),
                        diff=c(3,5,6,4,3))

table2 = data.frame( CGID=c("CG_2","CG_3","CG_4", "CG_1", "CG_5"),
                        diff=c(4,6,3,9,10))

newtable    <- merge(table1, table2, by="CGID")

matplot(merge(table1, table2, by="CGID")[,2:3])

or reshape() it :

newtable2   <- reshape(newtable,
                idvar="CGID",
                varying=list(names(newtable)[2:3]),
                v.names="diff",
                direction="long")

plot(diff ~ CGID, newtable2)        # if a good number of points
stripplot(diff ~ CGID, newtable2)   # if only two per CGID level


Marco Blanchette a écrit :

>Dear all,
>
>I am still fairly new to R and try to analyze large tables of data generated
>from genomic experiment. Currently, I am trying to plot pair of experiments
>coming from different file, trying to look at the behavior of individual
>feature in pair of experiment.
>
>My problem is that I have independent list from different source and I would
>like to plot the pair of value using a common key. As in this simplified
>version:
>
>table1 = list(CGID=c("CG_1","CG_3","CG_2", "CG_4", "CG_5"),
>diff=c(3,5,6,4,3))
>
>table2 = list(CGID=c("CG_2","CG_3","CG_4", "CG_1", "CG_5"),
>diff=c(4,6,3,9,10))
>
>How can link the two table trough the CGIDC column and plot the data from
>the 2 tables.
>
>Many tx
>
>Marco Blanchette, Ph.D.
>
>[hidden email]
>
>Donald C. Rio's lab
>Department of Molecular and Cell Biology
>16 Barker Hall
>University of California
>Berkeley, CA 94720-3204
>
>Tel: (510) 642-1084
>Cell: (510) 847-0996
>Fax: (510) 642-6062
>
>______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>  
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Merging lists on common key (was <no subject>)

Florence Combes
In reply to this post by Marc Schwartz (via MN)
Dear Marc, Dear all,

I saw your e-mail about "merge()" and I take the occasion to ask something
to you I already asked on the list but without success.
I searched long without finding, maybe you have a clue ...
I am looking for a function which performs the same as "merge()" but for
more than 2 lists, for example this would be :

> merge(table1, table2, ..., table(i), by = "common.variable")

Thanks a lot,

Florence.

--
R 2.2.0 (!) under Linux Debian.



On 12/15/05, Marc Schwartz <[hidden email]> wrote:

>
> On Wed, 2005-12-14 at 18:14 -0800, Marco Blanchette wrote:
> > Dear all,
> >
> > I am still fairly new to R and try to analyze large tables of data
> generated
> > from genomic experiment. Currently, I am trying to plot pair of
> experiments
> > coming from different file, trying to look at the behavior of individual
> > feature in pair of experiment.
> >
> > My problem is that I have independent list from different source and I
> would
> > like to plot the pair of value using a common key. As in this simplified
> > version:
> >
> > table1 = list(CGID=c("CG_1","CG_3","CG_2", "CG_4", "CG_5"),
> > diff=c(3,5,6,4,3))
> >
> > table2 = list(CGID=c("CG_2","CG_3","CG_4", "CG_1", "CG_5"),
> > diff=c(4,6,3,9,10))
> >
> > How can link the two table trough the CGIDC column and plot the data
> from
> > the 2 tables.
> >
> > Many tx
> >
> > Marco Blanchette, Ph.D.
>
> Marco,
>
> Please use an informative subject when posting. It makes it easier for
> folks, especially when reviewing the e-mail list archives.
>
> There is a function called merge() which will perform SQL-like joins.
>
> merge() will coerce the two lists to data frames, so you can do the
> following:
>
> > merge(table1, table2, by = "CGID")
>   CGID diff.x diff.y
> 1 CG_1      3      9
> 2 CG_2      6      4
> 3 CG_3      5      6
> 4 CG_4      4      3
> 5 CG_5      3     10
>
> The result is a join of the two lists, using CGID (quoted) as the
> primary key. The two 'diff' elements are uniquely named based upon their
> source objects (x and y arguments in merge()) as a suffix. The appended
> suffix can be changed if required.
>
> See ?merge for more information.
>
> HTH,
>
> Marc Schwartz
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: <no subject>

Sean Davis
In reply to this post by Marco Blanchette-3



On 12/14/05 9:14 PM, "Marco Blanchette" <[hidden email]> wrote:

> Dear all,
>
> I am still fairly new to R and try to analyze large tables of data generated
> from genomic experiment. Currently, I am trying to plot pair of experiments
> coming from different file, trying to look at the behavior of individual
> feature in pair of experiment.
>
> My problem is that I have independent list from different source and I would
> like to plot the pair of value using a common key. As in this simplified
> version:
>
> table1 = list(CGID=c("CG_1","CG_3","CG_2", "CG_4", "CG_5"),
> diff=c(3,5,6,4,3))
>
> table2 = list(CGID=c("CG_2","CG_3","CG_4", "CG_1", "CG_5"),
> diff=c(4,6,3,9,10))
>
> How can link the two table trough the CGIDC column and plot the data from
> the 2 tables.

 table1 <- data.frame( CGID=c("CG_1","CG_3","CG_2", "CG_4", "CG_5"),
diff=c(3,5,6,4,3))

 table2 <- data.frame( CGID=c("CG_2","CG_3","CG_4", "CG_1", "CG_5"),
diff=c(4,6,3,9,10))

 table.merged <- merge(table1,table2,by.x=1,by.y=1)

In other words, use a data.frame here and then use merge.

Does that do it?

Sean

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Loading...