Here's one way to extend the code to groups of 4 as well ...
Jean
# 3
df2 <- df
names(df2) <- paste0("new", 1:2)
df3 <- merge(df2, df, by.x="new2", by.y="V.1")[, c(2, 1, 3)]
names(df3) <- paste0("new", 1:3)
df3
# 4
df4 <- merge(df3, df, by.x="new3", by.y="V.1")[, c(2, 3, 1, 4)]
names(df4) <- pa
Hmmm. I'm not sure why you prefer 20-30 lines of looping code over a
simpler 1 line solution, but, as you wish.
merge(df, df, by.x="V.2", by.y="V.1")[, c(2, 1, 3)]
Jean
On Mon, Aug 5, 2013 at 12:37 PM, PQuery wrote:
> Hello Jean,
>
> Thanks for the reply. However, you solution doesn't reprod
Hello Jean,
Thanks for the reply. However, you solution doesn't reproduce the output
that I desire.
I updated my post with my solution full of loops.
If there is a more fancy/elegant way, I'll take it.
Best,
--
View this message in context:
http://r.789695.n4.nabble.com/obtain-triplets-fr
Try this:
merge(df, df, by.x="V2", by.y="V1")
Jean
On Mon, Aug 5, 2013 at 1:26 AM, PQuery wrote:
> Hi Guys,
>
> I have a list elements in two columns of a data frame. I want first to
> subselect on V1 and then to form and count all possible and unique triplets
> of V1 with the corresponding
Hi Guys,
I have a list elements in two columns of a data frame. I want first to
subselect on V1 and then to form and count all possible and unique triplets
of V1 with the corresponding elements in V2 but exclude triplets for which
a pair (V1 V2) does not exists:
Example input
V1 V2
AB
A
5 matches
Mail list logo