Re: [R] obtain triplets from Data Frame columns

2013-08-05 Thread Adams, Jean
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

Re: [R] obtain triplets from Data Frame columns

2013-08-05 Thread Adams, Jean
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

Re: [R] obtain triplets from Data Frame columns

2013-08-05 Thread PQuery
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

Re: [R] obtain triplets from Data Frame columns

2013-08-05 Thread Adams, Jean
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

[R] obtain triplets from Data Frame columns

2013-08-04 Thread PQuery
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