I guess I found a solution though it is not very elegant.
Hermann

snp.block <- function (huz)
    {
        for (i in names (huz))
             {
                 chain1 <- huz[[i]]
                 for (k in names (huz))
                     {
                         chain2 <- huz[[k]]
                         if (k==i)
                             {
                                 next
                             }
                         else if (length (intersect (chain1, chain2))!=0)
                             {
                                 chain3 <- union (chain1, chain2)
                                 chain1 <- chain3
                                 huz[[i]] <- sort (chain3)
                             }
                         else if (length (intersect (chain1, chain2)) == 0)
                             {
                                 chain3 <- chain1
                                 huz[[i]] <- sort (chain3)
                                 next
                             }
                     }
             }
        huz <- unique (huz)
        return (huz)
    }



2013/11/9 Hermann Norpois <hnorp...@gmail.com>

> Hello,
>
> I have a list called ja and I wish to unify list objects if there is some
> overlap.
> For instance something like
>
> if (length (intersect (ja[[1]], ja[[2]]) !=0) { union (ja[[1]], ja[[2]] }
>
> but of course it should work cumulatively (for larger data sets).
>
> Could you please give me a hint.
>
> Thanks
> Hermann
>
> > ja
> $A
> [1] "A" "B" "F" "G" "H"
>
> $B
> [1] "B" "F" "I"
>
> $C
> [1] "C" "F" "I" "K"
>
> $D
> [1] "D" "L" "M" "N"
>
> $L
> [1] "L" "O" "P"
>
>
> dput (ja)
> structure(list(A = c("A", "B", "F", "G", "H"), B = c("B", "F",
> "I"), C = c("C", "F", "I", "K"), D = c("D", "L", "M", "N"), L = c("L",
> "O", "P")), .Names = c("A", "B", "C", "D", "L"))
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to