Grokbase Groups R r-help June 2011
FAQ
Hi
Thanks Gabor for your suggestion. I am posting the code that worked for me.


dataframe1 = data.frame(cbind(Src = c(1,1,1,2,3), Target1 =
c('aaa','bbb','ccc','aaa','ddd'))); #must be data frame
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')));
dataframe4 = data.frame(cbind(Src = c(3,5,'y','z','z'), Target4 =
c('xx','yy','zz','tt','uu')));
L <- list(dataframe1, dataframe2, dataframe3, dataframe4)
merge.all <- function(...) merge(..., all = TRUE)
Reduce(merge.all, lapply(L, function(x) aggregate(x[2], x[1], toString)))

Cheers !!!

-
M

On Tue, Jun 14, 2011 at 11:27 AM, Gabor Grothendieck wrote:
On Tue, Jun 14, 2011 at 11:21 AM, Mary Kindall wrote:
I resolved it. There was a problem in type casting at some point in my
program.
Thanks again.
-
Please post a corrected version of L for benefit of others who were
following this.

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com


--
-------------
Mary Kindall
Yorktown Heights, NY
USA

Search Discussions

  • Gabor Grothendieck at Jun 14, 2011 at 3:52 pm

    On Tue, Jun 14, 2011 at 11:40 AM, Mary Kindall wrote:
    Hi
    Thanks Gabor for your suggestion. I am posting the code that worked for me.


    dataframe1 = data.frame(cbind(Src = c(1,1,1,2,3), Target1 =
    c('aaa','bbb','ccc','aaa','ddd')));? #must be data frame
    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')));
    dataframe4 = data.frame(cbind(Src = c(3,5,'y','z','z'), Target4 =
    c('xx','yy','zz','tt','uu')));
    L <- list(dataframe1, dataframe2, dataframe3, dataframe4)
    merge.all <- function(...) merge(..., all = TRUE)
    Reduce(merge.all, lapply(L, function(x) aggregate(x[2], x[1], toString)))
    Note that
    - cbind is not needed here
    - R statements need not be terminated with semicolons
    so the code can be slightly reduced as shown below.

    dataframe1 <- data.frame(Src = c(1,1,1,2,3), Target1 =
    c('aaa','bbb','ccc','aaa','ddd'))
    dataframe2 <- data.frame(Src = c(2,3,4,4,4), Target2 =
    c('aaaa','dddd','bbbb','eeee','ffff'))
    dataframe3 <- data.frame(Src = c(1,3,5,6,6), Target3 =
    c('xx','yy','zz','tt','uu'))
    dataframe4 <- data.frame(Src = c(3,5,'y','z','z'), Target4 =
    c('xx','yy','zz','tt','uu'))

    L <- list(dataframe1, dataframe2, dataframe3, dataframe4)
    merge.all <- function(...) merge(..., all = TRUE)
    Reduce(merge.all, lapply(L, function(x) aggregate(x[2], x[1], toString)))

    Also note that c(3, 5, 'y', 'z', 'z') will be converted to c('3', '5',
    'y', 'z', 'z').

    --
    Statistics & Software Consulting
    GKX Group, GKX Associates Inc.
    tel: 1-877-GKX-GROUP
    email: ggrothendieck at gmail.com

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedJun 14, '11 at 3:40p
activeJun 14, '11 at 3:52p
posts2
users2
websiter-project.org
irc#r

People

Translate

site design / logo © 2017 Grokbase