Re: [R] How to invert a list ?

2010-08-16 Thread Carlos Petti
) - c(NameA,NameB) Regards, Wu From: Carlos Petti [carlos.pe...@gmail.com] Sent: Wednesday, August 11, 2010 5:39 AM To: Wu Gong Cc: r-help@r-project.org Subject: Re: [R] How to invert a list ? Or rather : n - sapply(x, function(i) names(i

Re: [R] How to invert a list ?

2010-08-11 Thread Carlos Petti
Thanks. On the other hand, I try to obtain the same result but from this list : x - list() x$i - 5 x$j - 9 x$k - 15 names(x$i) - a names(x$j) - b names(x$k) - b Thanks in advance, Carlos 2010/8/10 Wu Gong w...@mtmail.mtsu.edu: Hi Carlos, I give a handmade code, hope it helps. y - list()

Re: [R] How to invert a list ?

2010-08-11 Thread Carlos Petti
A beginning of solution... n - sapply(x, function(i) names(i)) tapply(x, n, c) 2010/8/11 Carlos Petti carlos.pe...@gmail.com: Thanks. On the other hand, I try to obtain the same result but from this list : x - list() x$i - 5 x$j - 9 x$k - 15 names(x$i) - a names(x$j) - b names(x$k) -

Re: [R] How to invert a list ?

2010-08-11 Thread Carlos Petti
Or rather : n - sapply(x, function(i) names(i)) tapply(x, n, names) 2010/8/11 Carlos Petti carlos.pe...@gmail.com: A beginning of solution... n - sapply(x, function(i) names(i)) tapply(x, n, c) 2010/8/11 Carlos Petti carlos.pe...@gmail.com: Thanks. On the other hand, I try to obtain the

Re: [R] How to invert a list ?

2010-08-10 Thread Henrique Dallazuanna
Here is one way: xst - stack(x) let - letters[cumsum(duplicated(match(xst$ind, letters))) + match(xst$ind, letters)] with(xst, structure(split(structure(values, names = let), ind), .Names = row.names(xst)[1:length(unique(ind))])) On Tue, Aug 10, 2010 at 1:58 PM, Carlos Petti

Re: [R] How to invert a list ?

2010-08-10 Thread Wu Gong
Hi Carlos, I give a handmade code, hope it helps. y - list() y$a - a y$b - c(b,c) names(y$a) - i names(y$b) - c(j,k) Carlos Petti wrote: a - 5 names(a) - a b - 9 names(b) - b c - 15 names(c) - c x - list(i = a, j = b, j = c) - A R learner. -- View this message in context: